--- - name: Configure Prometheus for Blackbox monitoring hosts: 192.168.0.105 become: yes vars: blackbox_targets: # Основные сервисы стенда (из ИП) - "http://192.168.0.110/" - "http://192.168.0.111:9187/metrics" # postgres_exporter - "http://192.168.0.112:8080/get" # httpbin - "http://192.168.0.112:8081/metrics" # cadvisor - "http://192.168.0.100:3000/" # forgejo - "http://192.168.0.101:9100/metrics" # ansible node_exporter - "http://192.168.0.103:8200/ui/" # vault - "http://192.168.0.104:8428/metrics" # victoriametrics - "http://192.168.0.105:9090/metrics" # prometheus - "http://192.168.0.106:3000" # grafana # Основные домены (первые для теста) - "http://forgejo.pvenode.ru/" - "http://grafana.pvenode.ru/" - "http://prometheus.pvenode.ru/" - "http://app1.pvenode.ru/" - "http://wiki.pvenode.ru/" tasks: - name: Backup original Prometheus config copy: src: /etc/prometheus/prometheus.yml dest: /etc/prometheus/prometheus.yml.backup-{{ ansible_date_time.epoch }} remote_src: yes tags: prometheus - name: Add blackbox exporter to Prometheus blockinfile: path: /etc/prometheus/prometheus.yml insertafter: ' # cAdvisor container metrics' block: | # Blackbox Exporter probes - job_name: 'blackbox' metrics_path: /probe params: module: [http_2xx] static_configs: - targets: {% for target in blackbox_targets %} - "{{ target }}" {% endfor %} relabel_configs: - source_labels: [__address__] target_label: __param_target - source_labels: [__param_target] target_label: instance - target_label: __address__ replacement: 192.168.0.112:8083 # blackbox-exporter marker: "# {mark} ANSIBLE MANAGED BLOCK - blackbox" tags: prometheus - name: Check Prometheus configuration command: promtool check config /etc/prometheus/prometheus.yml register: promtool_check failed_when: promtool_check.rc != 0 tags: prometheus - name: Reload Prometheus systemd: name: prometheus state: reloaded when: promtool_check.rc == 0 tags: prometheus - name: Show configured targets debug: msg: "Added {{ blackbox_targets|length }} targets to blackbox monitoring" tags: prometheus