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