alloy(role): pull in alloy role that works from fux
All checks were successful
/ build (pull_request) Successful in 32s
/ Ansible Lint (push) Successful in 2m23s
/ Ansible Lint (pull_request) Successful in 2m25s

This commit is contained in:
chris 2026-07-09 21:13:57 +02:00
commit 0b5fa03ac3
Signed by: c6ristian
SSH key fingerprint: SHA256:B3m+yzpaxGXSEcDBpPHfvza/DNC0wuX+CKMeGq8wgak
246 changed files with 555 additions and 19211 deletions

View file

@ -0,0 +1,11 @@
---
- name: Render blackbox exporter config
tags: [ blackbox-exporter, alloy ]
become: true
ansible.builtin.template:
src: config.blackbox-exporter.j2
dest: /etc/alloy/blackbox-exporter.yaml
mode: "0644"
owner: root
notify:
- Alloy.reloaded

View file

@ -0,0 +1,20 @@
---
- name: Add grafana apt repo with signing key
become: true
ansible.builtin.deb822_repository:
name: grafana
types: deb
uris: https://apt.grafana.com
suites: stable
components:
- main
signed_by: https://apt.grafana.com/gpg.key
- name: Run cache update
ansible.builtin.apt:
update_cache: true
- name: Install alloy
become: true
ansible.builtin.package:
name: alloy

View file

@ -1,50 +1,79 @@
# https://github.com/grafana/grafana-ansible-collection/blob/main/roles/alloy/tasks/deploy.yml#L124
- name: ensure alloy user exists
ansible.builtin.user:
name: alloy
system: true
append: true
create_home: false
state: present
- name: ensure the `/etc/alloy/` config directory exists
ansible.builtin.file:
path: /etc/alloy
state: directory
mode: "0770"
owner: root
group: alloy
become: true
- name: synchronize the additional configuration files directory, if present
when: alloy__additional_configs_dir is defined and alloy__additional_configs_dir != ""
---
- name: Deploy Grafana Alloy with config
tags: [ alloy ]
block:
- name: ensure rsync is installed
ansible.builtin.apt:
name: rsync
- 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: synchronize the additional configuration files directory, if present
ansible.posix.synchronize:
src: "{{ alloy__additional_configs_dir }}"
dest: /etc/alloy/additional
delete: true
recursive: true
use_ssh_args: true
rsync_opts:
- "--chown=root:alloy"
- 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: delete the additional configuration files directory, if not present
when: alloy__additional_configs_dir is not defined or alloy__additional_configs_dir == ""
ansible.builtin.file:
path: /etc/alloy/additional
state: absent
become: true
- 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: Setup Alloy
ansible.builtin.import_role:
name: grafana.grafana.alloy
vars:
alloy_config: "{{ alloy_config_default ~ alloy_config_additional }}"
become: true
- 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

View file

@ -0,0 +1,76 @@
---
- name: Install and Setup unpoller
tags: [ unpoller, alloy, podman, container ]
block:
- name: Install Podman
become: true
ansible.builtin.package:
name:
- podman
- fuse-overlayfs
- name: Create unpoller group
become: true
register: alloy_unpoller_group
ansible.builtin.group:
name: unpoller
- name: Create unpoller user
become: true
register: alloy_unpoller_user
ansible.builtin.user:
name: unpoller
group: unpoller
system: true
- name: Create unpoller configuration directory
become: true
ansible.builtin.file:
path: /etc/unpoller
state: directory
owner: "{{ alloy_unpoller_user.name }}"
mode: "0755"
- name: Render unpoller configuration
become: true
notify: Unpoller.restarted
ansible.builtin.template:
src: unpoller.conf.j2
dest: /etc/unpoller/up.conf
owner: "{{ alloy_unpoller_user.name }}"
mode: "0644"
- name: Create /etc/containers/systemd directory
become: true
ansible.builtin.file:
path: /etc/containers/systemd
state: directory
owner: root
mode: "0755"
- name: Configure unpoller quadlet
become: true
notify: Unpoller.restarted
register: alloy_unpoller_quadlet
vars:
container_image_with_tag: ghcr.io/unpoller/unpoller:v2
container_unit_args:
container_exec:
container_envs: [ ]
container_volumes:
- { host: "/etc/unpoller", inside: "/etc/unpoller:ro" }
user_id: "{{ alloy_unpoller_user.uid }}"
group_id: "{{ alloy_unpoller_group.gid }}"
ansible.builtin.template:
src: podman.container.jinja
dest: /etc/containers/systemd/unpoller.container
owner: root
mode: "0644"
- name: Ensure unpoller is running and enabled
become: true
ansible.builtin.systemd:
name: unpoller.service
state: started
enabled: true
daemon_reload: "{{ alloy_unpoller_quadlet.changed }}"