--- - name: generate apt pin file for exporter-nut package when: prometheus_exporter_nut_version is defined copy: dest: "/etc/apt/preferences.d/prom-exporter-nut.pref" content: | Package: prom-exporter-nut Pin: version {{ prometheus_exporter_nut_version }}-1 Pin-Priority: 1001 - name: remove apt pin file for exporter-nut package when: prometheus_exporter_nut_version is not defined file: path: "/etc/apt/preferences.d/prom-exporter-nut.pref" state: absent - name: install apt packages apt: name: "prom-exporter-nut{% if prometheus_exporter_nut_version is defined %}={{ prometheus_exporter_nut_version }}-1{% endif %}" state: present allow_downgrade: yes notify: restart prometheus-nut-exporter - name: generate systemd service unit template: src: service.j2 dest: /etc/systemd/system/prometheus-nut-exporter.service notify: restart prometheus-nut-exporter - name: make sure prometheus-nut-exporter is enabled and started systemd: name: prometheus-nut-exporter.service daemon_reload: yes state: started enabled: yes - name: register exporter copy: content: | location = /nut { proxy_pass http://127.0.0.1:9199/metrics; } location = /nut/ups { proxy_pass http://127.0.0.1:9199/ups_metrics; } dest: /etc/prometheus/exporter/nut.locations notify: reload nginx