pez-infra/ansible/roles/alloy/tasks/main.yml

89 lines
3.1 KiB
YAML

---
# Install and configure Grafana Alloy log shipping agent.
# Debian/Ubuntu: alloy package (included in default repos).
# Alpine: alloy package (included in default repos).
# FreeBSD: pkgng (grafana-alloy).
# ── Debian/Ubuntu ────────────────────────────────────────────────────────────
- name: Install alloy (Debian)
ansible.builtin.apt:
name: alloy
state: present
when: ansible_facts["os_family"] == "Debian"
# ── Alpine ───────────────────────────────────────────────────────────────────
- name: Install alloy (Alpine)
community.general.apk:
name: alloy
state: present
when: ansible_facts["os_family"] == "Alpine"
# ── FreeBSD: pkgng ────────────────────────────────────────────────────────────
- name: Install alloy (FreeBSD)
community.general.pkgng:
name: alloy
state: present
when: ansible_facts["os_family"] == "FreeBSD"
- name: Create alloy directories (FreeBSD)
ansible.builtin.file:
path: "{{ item }}"
state: directory
mode: '0755'
loop:
- /usr/local/etc/alloy
- /var/db/alloy
when: ansible_facts["os_family"] == "FreeBSD"
# ── Config — all OS ───────────────────────────────────────────────────────────
- name: Set alloy config path fact
ansible.builtin.set_fact:
alloy_config_path: >-
{{ '/usr/local/etc/alloy/config.alloy'
if ansible_facts['os_family'] == 'FreeBSD'
else '/etc/alloy/config.alloy' }}
- name: Deploy alloy config
ansible.builtin.template:
src: alloy.config.alloy.j2
dest: "{{ alloy_config_path }}"
mode: '0644'
notify: "Restart alloy ({{ ansible_facts['os_family'] }})"
# ── Service enable + start ────────────────────────────────────────────────────
- name: Enable and start alloy (Debian)
ansible.builtin.service:
name: alloy
state: started
enabled: true
when: ansible_facts["os_family"] == "Debian"
- name: Enable and start alloy (Alpine)
ansible.builtin.service:
name: alloy
state: started
enabled: true
when: ansible_facts["os_family"] == "Alpine"
- name: Enable alloy (FreeBSD)
community.general.sysrc:
name: alloy_enable
value: "YES"
when: ansible_facts["os_family"] == "FreeBSD"
- name: Set alloy config in rc.conf (FreeBSD)
community.general.sysrc:
name: alloy_config
value: /usr/local/etc/alloy/config.alloy
when: ansible_facts["os_family"] == "FreeBSD"
- name: Start alloy (FreeBSD)
ansible.builtin.service:
name: alloy
state: started
when: ansible_facts["os_family"] == "FreeBSD"