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