diff --git a/roles/alloy/README.md b/roles/alloy/README.md new file mode 100644 index 0000000..6e7b809 --- /dev/null +++ b/roles/alloy/README.md @@ -0,0 +1,28 @@ +# `Grafana Alloy` role + +Installs and configures [Grafana Alloy](https://grafana.com/docs/alloy/latest/) on Debian-based systems. +Optionally deploys a [Blackbox exporter](https://github.com/prometheus/blackbox_exporter) config and a [UniFi Poller](https://unpoller.com/). + +## Supported Distributions + +Should work on Debian-based distributions. + +## Required Arguments + +- `alloy_config_default`: The default Alloy configuration. Recomanded for configuration that hosts of a groupe share. + +## Optional Arguments + +- `alloy_config_additional`: Additional Alloy configuration appended to the default config. Recomanded for per host configuration +- `alloy_cap_net_bind_service`: Grant Alloy the `CAP_NET_BIND_SERVICE` capability, allowing it to bind to privileged ports (<1024). + +### Blackbox Exporter +- `alloy_blackbox_exporter_config_default`: Default blackbox exporter configuration. +- `alloy_blackbox_exporter_config_additional`: Additional blackbox exporter configuration appended to the default blackbox exporter config. + +### UniFi Poller + +- `alloy_unpoller_enabled`: Enable the UniFi Poller container to scrape UniFi metrics. +- `alloy_unpoller_unifi_user`: Username for the UniFi controller used by unpoller, defaults to `unpoller`. +- `alloy_unpoller_unifi_password`: Password for the UniFi controller. Required when `alloy_unpoller_enabled` is `true`. +- `alloy_unpoller_unifi_url`: URL of the UniFi controller. Required when `alloy_unpoller_enabled` is `true`. diff --git a/roles/alloy/defaults/main.yaml b/roles/alloy/defaults/main.yaml index c2b326a..2b08d27 100644 --- a/roles/alloy/defaults/main.yaml +++ b/roles/alloy/defaults/main.yaml @@ -1,6 +1,5 @@ --- alloy_cap_net_bind_service: false -alloy_do_we_have_v6: "{{ (ansible_facts['all_ipv6_addresses'] | select('match', '^[23]') | list | length > 0) | ternary('true', 'false') }}" alloy_config_default: | prometheus.remote_write "default" { diff --git a/roles/alloy/meta/argument_specs.yaml b/roles/alloy/meta/argument_specs.yaml new file mode 100644 index 0000000..a71dfc1 --- /dev/null +++ b/roles/alloy/meta/argument_specs.yaml @@ -0,0 +1,33 @@ +argument_specs: + main: + options: + alloy_config_default: + type: str + required: true + alloy_config_additional: + type: str + required: false + alloy_blackbox_exporter_config_default: + type: str + required: false + alloy_blackbox_exporter_config_additional: + type: str + required: false + alloy_cap_net_bind_service: + type: bool + required: false + default: false + alloy_unpoller_enabled: + type: bool + required: false + default: false + alloy_unpoller_unifi_user: + type: str + required: false + default: unpoller + alloy_unpoller_unifi_password: + type: str + required: false + alloy_unpoller_unifi_url: + type: str + required: false diff --git a/roles/alloy/tasks/blackbox-exporter.yaml b/roles/alloy/tasks/blackbox-exporter.yaml index b4e784d..1d6c0cc 100644 --- a/roles/alloy/tasks/blackbox-exporter.yaml +++ b/roles/alloy/tasks/blackbox-exporter.yaml @@ -1,6 +1,5 @@ --- - name: Render blackbox exporter config - tags: [ blackbox-exporter, alloy ] become: true ansible.builtin.template: src: config.blackbox-exporter.j2 diff --git a/roles/alloy/tasks/install_debian.yml b/roles/alloy/tasks/install.yaml similarity index 87% rename from roles/alloy/tasks/install_debian.yml rename to roles/alloy/tasks/install.yaml index 438e5d5..68b2963 100644 --- a/roles/alloy/tasks/install_debian.yml +++ b/roles/alloy/tasks/install.yaml @@ -5,7 +5,7 @@ name: grafana types: deb uris: https://apt.grafana.com - suites: stable + suites: "{{ ansible_facts['distribution_release'] }}" components: - main signed_by: https://apt.grafana.com/gpg.key diff --git a/roles/alloy/tasks/main.yaml b/roles/alloy/tasks/main.yaml index 69ceb63..aa3176e 100644 --- a/roles/alloy/tasks/main.yaml +++ b/roles/alloy/tasks/main.yaml @@ -2,9 +2,8 @@ - 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: Install Alloy + ansible.builtin.include_tasks: install.yaml - name: Create systemd override for alloy become: true diff --git a/roles/alloy/tasks/unpoller.yaml b/roles/alloy/tasks/unpoller.yaml index ceefbbb..23aff44 100644 --- a/roles/alloy/tasks/unpoller.yaml +++ b/roles/alloy/tasks/unpoller.yaml @@ -1,6 +1,5 @@ --- - name: Install and Setup unpoller - tags: [ unpoller, alloy, podman, container ] block: - name: Install Podman become: true diff --git a/roles/alloy/vars/main.yaml b/roles/alloy/vars/main.yaml index d9fbe4b..d6d88db 100644 --- a/roles/alloy/vars/main.yaml +++ b/roles/alloy/vars/main.yaml @@ -1,2 +1,3 @@ --- alloy_enable_blackbox_exporter: "{{ 'prometheus.exporter.blackbox' in (alloy_config_default + alloy_config_additional) }}" +alloy_do_we_have_v6: "{{ (ansible_facts['all_ipv6_addresses'] | select('match', '^[23]') | list | length > 0) | ternary('true', 'false') }}"