dnsservice/ansible/tasks/alloy.yml
2025-10-06 22:19:55 -05:00

81 lines
2.1 KiB
YAML

---
- name: Stop and disable Prometheus services
block:
- name: Stop and disable prometheus
ansible.builtin.service:
name: prometheus
state: stopped
enabled: no
ignore_errors: yes
- name: Stop and disable prometheus-node-exporter
ansible.builtin.service:
name: prometheus-node-exporter
state: stopped
enabled: no
ignore_errors: yes
- name: Install Grafana Alloy
block:
- name: Create keyrings directory
ansible.builtin.file:
path: /etc/apt/keyrings
state: directory
mode: '0755'
- name: Download Grafana GPG key
ansible.builtin.get_url:
url: https://apt.grafana.com/gpg.key
dest: /etc/apt/keyrings/grafana.asc
mode: '0644'
force: yes
- name: Add Grafana repository
ansible.builtin.apt_repository:
repo: "deb [signed-by=/etc/apt/keyrings/grafana.asc] https://apt.grafana.com stable main"
state: present
update_cache: yes
filename: grafana
- name: Install Alloy
ansible.builtin.apt:
name: alloy
state: present
update_cache: yes
- name: Create Alloy configuration directory
ansible.builtin.file:
path: /etc/alloy
state: directory
mode: '0755'
- name: Copy Alloy configuration
template:
src: "{{ playbook_dir }}/files/alloy.river"
dest: /etc/alloy/config.river
mode: '0644'
notify: restart alloy
- name: Add alloy user to systemd-journal and adm groups
ansible.builtin.user:
name: alloy
groups: systemd-journal,adm
append: yes
notify: restart alloy
- name: Copy Alloy systemd service file
ansible.builtin.copy:
src: "{{ playbook_dir }}/files/alloy.service"
dest: /etc/systemd/system/alloy.service
mode: '0644'
notify:
- reload systemd
- restart alloy
- name: Enable and start Alloy service
ansible.builtin.systemd:
name: alloy
enabled: yes
state: started
daemon_reload: yes