--- - name: generate apt pin file for exporter-snmp package when: prometheus_exporter_snmp_version is defined copy: dest: "/etc/apt/preferences.d/prom-exporter-snmp.pref" content: | Package: prom-exporter-snmp Pin: version {{ prometheus_exporter_snmp_version }}-1 Pin-Priority: 1001 - name: remove apt pin file for exporter-snmp package when: prometheus_exporter_snmp_version is not defined file: path: "/etc/apt/preferences.d/prom-exporter-snmp.pref" state: absent - name: install apt packages apt: name: "prom-exporter-snmp{% if prometheus_exporter_snmp_version is defined %}={{ prometheus_exporter_snmp_version }}-1{% endif %}" state: present allow_downgrade: yes notify: restart prometheus-snmp-exporter - name: overwrite default configuration when: prometheus_exporter_snmp_config_default is defined copy: content: | # Ansible managed {{ prometheus_exporter_snmp_config_default | to_nice_yaml(indent=2) }} dest: /etc/prometheus/exporter/snmp/config-default.yml notify: reload prometheus-snmp-exporter - name: generate extra configuration when: prometheus_exporter_snmp_config_extra is defined copy: content: | # Ansible managed {{ prometheus_exporter_snmp_config_extra | to_nice_yaml(indent=2) }} dest: /etc/prometheus/exporter/snmp/config-extra.yml notify: reload prometheus-snmp-exporter - name: generate systemd service unit template: src: service.j2 dest: /etc/systemd/system/prometheus-snmp-exporter.service notify: restart prometheus-snmp-exporter - name: make sure prometheus-snmp-exporter is enabled and started systemd: name: prometheus-snmp-exporter.service daemon_reload: yes state: started enabled: yes - name: register exporter copy: content: | location = /snmp { proxy_pass http://127.0.0.1:9116/metrics; } location = /snmp/probe { proxy_pass http://127.0.0.1:9116/snmp; } dest: /etc/prometheus/exporter/snmp.locations notify: reload nginx