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