systemd unit for the prometheus server. Also, do not overwrite the configuration file.

This commit is contained in:
Andrea Dell'Amico 2018-04-19 19:48:50 +02:00
parent 6e6850d139
commit f5b5e06629
3 changed files with 27 additions and 5 deletions

View File

@ -1,6 +1,6 @@
---
prometheus_install: True
prometheus_version: 2.1.0
prometheus_version: 2.2.1
prometheus_dir: 'prometheus-{{ prometheus_version }}.linux-amd64'
prometheus_file: '{{ prometheus_dir }}.tar.gz'
prometheus_download_url: 'https://github.com/prometheus/prometheus/releases/download/v{{ prometheus_version }}/{{ prometheus_file }}'

View File

@ -0,0 +1,16 @@
[Unit]
Description=Prometheus - Prometheus metrics collector.
Documentation=https://prometheus.io/docs/introduction/overview/
After=network.target
[Service]
Type=simple
User={{ prometheus_user }}
Group={{ prometheus_user }}
EnvironmentFile=/etc/default/prometheus
ExecStart=${PROMETHEUS_CMD} --config.file=${PROMETHEUS_CONF} --storage.tsdb.path=${PROMETHEUS_DATADIR} --log.level=${PROMETHEUS_LOGLEVEL} ${PROMETHEUS_OPTS}
Restart=on-failure
[Install]
WantedBy=multi-user.target

View File

@ -26,15 +26,21 @@
notify: Restart prometheus
- name: Install the prometheus configuration
template: src=prometheus.yml.j2 dest={{ prometheus_confdir }}/prometheus.yml
template: src=prometheus.yml.j2 dest={{ prometheus_confdir }}/prometheus.yml force=no
notify: Reload prometheus
- name: Install the prometheus upstart script
copy: src=prometheus.upstart dest=/etc/init/prometheus.conf mode=0644 owner=root group=root
- name: Install the prometheus defaults
template: src=prometheus.default.j2 dest=/etc/default/prometheus mode=0644 owner=root group=root
- name: Install the prometheus upstart script
copy: src=prometheus.upstart dest=/etc/init/prometheus.conf mode=0644 owner=root group=root
when: ansible_service_mgr != 'systemd'
- name: Install the prometheus server systemd unit
copy: src=prometheus.systemd dest=/etc/systemd/system/prometheus.service mode=0644 owner=root group=root
when: ansible_service_mgr == 'systemd'
notify: systemd reload
- name: Ensure that prometheus is started and enabled
service: name=prometheus state=started enabled=yes