--- - name: Load variables include_vars: "{{ ansible_os_family|lower }}.yml" - name: Install Prometheus tags: prometheus-install ansible.builtin.package: name: '{{ prometheus_package }}' state: latest - name: Add scrape configuration tags: prometheus-scrape-configure ansible.builtin.copy: src: "{{ item.src }}" dest: "/etc/prometheus/{{ item.dest }}" loop: - { src: '../templates/scrape-main.yml', dest: 'scrape-main.yml' } - { src: '../templates/scrape-blackbox.yml', dest: 'scrape-blackbox.yml' } notify: - restart prometheus - name: Create folder for rules definition ansible.builtin.file: path: /etc/prometheus/rules state: directory mode: 0755 - name: Add rules configuration tags: alertmanager-rules-configure ansible.builtin.copy: src: "{{ item.src }}" dest: "{{ alertmanager_rules }}/{{ item.dest }}" loop: - { src: '../templates/hosts.rules', dest: 'hosts.rules.yml' } - { src: '../templates/prometheus.rules', dest: 'prometheus.rules.yml' } - { src: '../templates/blackbox.rules', dest: 'blackbox.rules.yml' } notify: - restart prometheus - restart alertmanager - name: Enable Prometheus configuration tags: prometheus-configure ansible.builtin.template: src: prometheus.config.j2 dest: '{{ prometheus_config }}' validate: promtool check config %s notify: restart prometheus - name: Enable Prometheus service tags: prometheus-enable ansible.builtin.service: name: '{{ prometheus_service }}' state: started enabled: yes - name: Enable Alertmanager service tags: alertmanager-enable ansible.builtin.service: name: '{{ alertmanager_service }}' state: started enabled: yes