--- - name: Deploy Grafana Alloy with config tags: [ alloy ] block: - name: Install Alloy on Debian when: ansible_facts['distribution'] == "Debian" ansible.builtin.include_tasks: install_debian.yml - name: Create systemd override for alloy become: true when: alloy_cap_net_bind_service notify: Systemd.daemon_reload block: - name: Create systemd override directory ansible.builtin.file: path: /etc/systemd/system/alloy.service.d state: directory mode: "0755" owner: root group: root - name: Add CAP_NET_BIND_SERVICE capability ansible.builtin.copy: dest: /etc/systemd/system/alloy.service.d/override.conf mode: "0755" owner: root group: root content: | [Service] AmbientCapabilities=CAP_NET_BIND_SERVICE - name: Deploy the Alloy config file become: true ansible.builtin.template: src: "config.alloy.j2" dest: "/etc/alloy/config.alloy" owner: "alloy" group: "alloy" mode: "0640" notify: - Alloy.restarted - Alloy.enabled - name: Validate Alloy configuration and print error if failed block: - name: Validate Alloy configuration become: true register: alloy_validation changed_when: false ansible.builtin.command: alloy validate /etc/alloy/config.alloy rescue: - name: Show error if validation failed when: alloy_validation.rc != 0 ansible.builtin.fail: msg: | Alloy configuration validation failed! Return code: {{ alloy_validation.rc }} Stdout: {{ alloy_validation.stdout }} Stderr: {{ alloy_validation.stderr }} - name: Deploy blackbox-exporter config when: alloy_enable_blackbox_exporter ansible.builtin.include_tasks: blackbox-exporter.yaml - name: Deploy unpoller exporter when: alloy_unpoller_enabled ansible.builtin.include_tasks: unpoller.yaml - name: Flush handlers ansible.builtin.meta: flush_handlers - name: Ensure that Alloy is working ansible.builtin.uri: url: "http://localhost:12345/-/ready" method: GET register: alloy_status_code retries: 8 delay: 6 until: not alloy_status_code.failed