mirror of
https://github.com/RWejlgaard/pez-infra.git
synced 2026-05-06 04:14:43 +00:00
Compare commits
3 commits
5391c500e1
...
a51a0879d3
| Author | SHA1 | Date | |
|---|---|---|---|
| a51a0879d3 | |||
| 6a3618aa4a | |||
| b474e28528 |
3 changed files with 18 additions and 122 deletions
|
|
@ -1,4 +1,2 @@
|
|||
---
|
||||
# Used for Alpine binary download only; Debian uses the Grafana apt repo.
|
||||
alloy_version: "1.5.1"
|
||||
alloy_loki_url: "http://{{ hostvars['london-a']['ansible_host'] }}:3100/loki/api/v1/push"
|
||||
|
|
|
|||
|
|
@ -1,43 +1,10 @@
|
|||
---
|
||||
# Install and configure Grafana Alloy log shipping agent.
|
||||
# Debian/Ubuntu: Grafana apt repo + alloy package.
|
||||
# Alpine: musl binary download from GitHub + OpenRC init script.
|
||||
# Debian/Ubuntu: alloy package (included in default repos).
|
||||
# Alpine: alloy package (included in default repos).
|
||||
# FreeBSD: pkgng (grafana-alloy).
|
||||
|
||||
# ── Debian/Ubuntu: Grafana apt repo ─────────────────────────────────────────
|
||||
|
||||
- name: Create apt keyrings directory (Debian)
|
||||
ansible.builtin.file:
|
||||
path: /etc/apt/keyrings
|
||||
state: directory
|
||||
mode: '0755'
|
||||
when: ansible_facts["os_family"] == "Debian"
|
||||
|
||||
- name: Set architecture fact
|
||||
ansible.builtin.set_fact:
|
||||
alloy_arch: >-
|
||||
{{ ansible_facts['architecture']
|
||||
| regex_replace('x86_64', 'amd64')
|
||||
| regex_replace('aarch64', 'arm64') }}
|
||||
when: ansible_facts["os_family"] in ["Debian", "Alpine"]
|
||||
|
||||
- name: Add Grafana GPG key (Debian)
|
||||
ansible.builtin.get_url:
|
||||
url: https://apt.grafana.com/gpg.key
|
||||
dest: /etc/apt/keyrings/grafana.gpg
|
||||
mode: '0644'
|
||||
force: false
|
||||
when: ansible_facts["os_family"] == "Debian"
|
||||
|
||||
- name: Add Grafana apt repository (Debian)
|
||||
ansible.builtin.apt_repository:
|
||||
repo: >-
|
||||
deb [arch={{ alloy_arch }} signed-by=/etc/apt/keyrings/grafana.gpg]
|
||||
https://apt.grafana.com stable main
|
||||
filename: grafana
|
||||
state: present
|
||||
update_cache: true
|
||||
when: ansible_facts["os_family"] == "Debian"
|
||||
# ── Debian/Ubuntu ────────────────────────────────────────────────────────────
|
||||
|
||||
- name: Install alloy (Debian)
|
||||
ansible.builtin.apt:
|
||||
|
|
@ -45,79 +12,14 @@
|
|||
state: present
|
||||
when: ansible_facts["os_family"] == "Debian"
|
||||
|
||||
# ── Alpine: binary download (musl build) ─────────────────────────────────────
|
||||
# ── Alpine ───────────────────────────────────────────────────────────────────
|
||||
|
||||
- name: Create alloy directories (Alpine)
|
||||
ansible.builtin.file:
|
||||
path: "{{ item }}"
|
||||
state: directory
|
||||
mode: '0755'
|
||||
loop:
|
||||
- /etc/alloy
|
||||
- /var/lib/alloy/data
|
||||
- name: Install alloy (Alpine)
|
||||
community.general.apk:
|
||||
name: alloy
|
||||
state: present
|
||||
when: ansible_facts["os_family"] == "Alpine"
|
||||
|
||||
- name: Check if alloy binary exists (Alpine)
|
||||
ansible.builtin.stat:
|
||||
path: /usr/local/bin/alloy
|
||||
register: alloy_bin
|
||||
when: ansible_facts["os_family"] == "Alpine"
|
||||
|
||||
- name: Get installed alloy version (Alpine)
|
||||
ansible.builtin.command: /usr/local/bin/alloy --version
|
||||
register: alloy_installed_version
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
when:
|
||||
- ansible_facts["os_family"] == "Alpine"
|
||||
- alloy_bin.stat.exists
|
||||
|
||||
- name: Download and install alloy binary (Alpine)
|
||||
when:
|
||||
- ansible_facts["os_family"] == "Alpine"
|
||||
- not alloy_bin.stat.exists or
|
||||
alloy_version not in (alloy_installed_version.stdout | default(''))
|
||||
block:
|
||||
- name: Download alloy musl zip
|
||||
ansible.builtin.get_url:
|
||||
url: >-
|
||||
https://github.com/grafana/alloy/releases/download/v{{ alloy_version
|
||||
}}/alloy-linux-{{ alloy_arch }}-musl.zip
|
||||
dest: /tmp/alloy.zip
|
||||
mode: '0644'
|
||||
|
||||
- name: Extract alloy binary
|
||||
ansible.builtin.unarchive:
|
||||
src: /tmp/alloy.zip
|
||||
dest: /tmp
|
||||
remote_src: true
|
||||
|
||||
- name: Install alloy binary
|
||||
ansible.builtin.copy:
|
||||
src: "/tmp/alloy-linux-{{ alloy_arch }}-musl"
|
||||
dest: /usr/local/bin/alloy
|
||||
mode: '0755'
|
||||
owner: root
|
||||
group: root
|
||||
remote_src: true
|
||||
notify: Restart alloy (Alpine)
|
||||
|
||||
- name: Clean up alloy download
|
||||
ansible.builtin.file:
|
||||
path: "{{ item }}"
|
||||
state: absent
|
||||
loop:
|
||||
- /tmp/alloy.zip
|
||||
- "/tmp/alloy-linux-{{ alloy_arch }}-musl"
|
||||
|
||||
- name: Deploy alloy OpenRC init script (Alpine)
|
||||
ansible.builtin.template:
|
||||
src: alloy_openrc.j2
|
||||
dest: /etc/init.d/alloy
|
||||
mode: '0755'
|
||||
when: ansible_facts["os_family"] == "Alpine"
|
||||
notify: Restart alloy (Alpine)
|
||||
|
||||
# ── FreeBSD: pkgng ────────────────────────────────────────────────────────────
|
||||
|
||||
- name: Install alloy (FreeBSD)
|
||||
|
|
@ -136,6 +38,16 @@
|
|||
- /var/db/alloy
|
||||
when: ansible_facts["os_family"] == "FreeBSD"
|
||||
|
||||
# ── Docker socket access ─────────────────────────────────────────────────────
|
||||
|
||||
- name: Add alloy to docker group
|
||||
ansible.builtin.user:
|
||||
name: alloy
|
||||
groups: docker
|
||||
append: true
|
||||
when: "'docker_hosts' in group_names"
|
||||
notify: "Restart alloy ({{ ansible_facts['os_family'] }})"
|
||||
|
||||
# ── Config — all OS ───────────────────────────────────────────────────────────
|
||||
|
||||
- name: Set alloy config path fact
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
#!/sbin/openrc-run
|
||||
# Ansible managed
|
||||
|
||||
name="alloy"
|
||||
description="Grafana Alloy log shipping agent"
|
||||
command="/usr/local/bin/alloy"
|
||||
command_args="run --storage.path=/var/lib/alloy/data /etc/alloy/config.alloy"
|
||||
command_background=true
|
||||
pidfile="/run/${RC_SVCNAME}.pid"
|
||||
|
||||
depend() {
|
||||
need net
|
||||
use logger
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue