--- - name: generate apt pin file for exporter-chrony package when: prometheus_exporter_chrony_version is defined copy: dest: "/etc/apt/preferences.d/prom-exporter-chrony.pref" content: | Package: prom-exporter-chrony Pin: version {{ prometheus_exporter_chrony_version }}-1 Pin-Priority: 1001 - name: remove apt pin file for exporter-chrony package when: prometheus_exporter_chrony_version is not defined file: path: "/etc/apt/preferences.d/prom-exporter-chrony.pref" state: absent - name: install apt packages apt: name: "prom-exporter-chrony{% if prometheus_exporter_chrony_version is defined %}={{ prometheus_exporter_chrony_version }}-1{% endif %}" state: present allow_downgrade: yes notify: restart prometheus-chrony-exporter - name: generate systemd service unit template: src: service.j2 dest: /etc/systemd/system/prometheus-chrony-exporter.service notify: restart prometheus-chrony-exporter - name: make sure prometheus-chrony-exporter is enabled and started systemd: name: prometheus-chrony-exporter.service daemon_reload: yes state: started enabled: yes - name: register exporter copy: content: | location = /chrony { proxy_pass http://127.0.0.1:9123/metrics; } dest: /etc/prometheus/exporter/chrony.locations notify: reload nginx ## TODO: remove these tasks once all hosts have been migrated - name: make sure the systemd timer for chrony textfile collector is disabled and stopped systemd: service: prometheus-node-exporter_chrony.timer enabled: no state: stopped register: result_systemd_stop failed_when: "result_systemd_stop is failed and 'Could not find the requested service' not in result_systemd_stop.msg" - name: remove files from chrony textfile collector loop: - /etc/systemd/system/prometheus-node-exporter_chrony.timer - /etc/systemd/system/prometheus-node-exporter_chrony.service - /usr/local/share/prometheus-node-exporter/chrony - /var/lib/prometheus-node-exporter/textfile-collector/chrony.prom file: path: "{{ item }}" state: absent notify: reload systemd