fix: remove custom node_exporter, standardise on package version (#40)

london-b had both a custom node_exporter.service and the
package-managed prometheus-node-exporter.service installed.
Both tried to bind port 9100, causing the package version to fail.

- Add cleanup tasks to remove custom /etc/systemd/system/node_exporter.service
  and /usr/local/bin/node_exporter if present
- Add node_exporter_extra_collectors variable for configurable collectors
- Configure london-b with systemd/processes/sysctl/ethtool/zfs collectors
  matching its previous custom setup

Resolves PESO-109
This commit is contained in:
Rasmus Wejlgaard 2026-04-03 01:50:13 +01:00 committed by GitHub
parent 20274d49d4
commit 853386ce2f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 50 additions and 3 deletions

View file

@ -15,6 +15,13 @@ docker_services:
zfs_pools:
- hdd
node_exporter_extra_collectors:
- systemd
- processes
- sysctl
- ethtool
- zfs
common_ufw_allowed_ports:
- {port: 32400, proto: tcp, comment: "Plex Media Server"}
- {port: 6881, proto: tcp, comment: "BitTorrent"}

View file

@ -2,3 +2,7 @@
# When true, bind node_exporter to the Tailscale IP (ansible_host) only.
# Use on public-facing hosts to avoid exposing metrics on 0.0.0.0.
node_exporter_bind_tailscale: false
# Extra collectors to enable beyond the defaults.
# Each entry is a collector name (e.g. "systemd", "processes").
node_exporter_extra_collectors: []

View file

@ -1,4 +1,8 @@
---
- name: Reload systemd
ansible.builtin.systemd:
daemon_reload: true
- name: Restart node-exporter (Debian)
ansible.builtin.service:
name: prometheus-node-exporter

View file

@ -3,6 +3,29 @@
# Uses system packages on Linux, pkg on FreeBSD.
# Optionally binds to Tailscale IP on public-facing hosts.
# ── Cleanup old custom installs ──────────────────────────────
- name: Stop and disable custom node_exporter service if present
ansible.builtin.service:
name: node_exporter
state: stopped
enabled: false
failed_when: false
when: ansible_facts["os_family"] == "Debian"
- name: Remove custom node_exporter service file
ansible.builtin.file:
path: /etc/systemd/system/node_exporter.service
state: absent
when: ansible_facts["os_family"] == "Debian"
notify: Reload systemd
- name: Remove custom node_exporter binary
ansible.builtin.file:
path: /usr/local/bin/node_exporter
state: absent
when: ansible_facts["os_family"] == "Debian"
# ── Install ──────────────────────────────────────────────────
- name: Install prometheus-node-exporter (Debian)
ansible.builtin.apt:
name: prometheus-node-exporter
@ -15,14 +38,22 @@
state: present
when: ansible_facts["os_family"] == "Alpine"
- name: Configure listen address (Debian)
# ── Configure (Debian) ──────────────────────────────────────
- name: Build ARGS for prometheus-node-exporter
ansible.builtin.set_fact:
_node_exporter_args: >-
{{ (node_exporter_extra_collectors | map('regex_replace', '^(.*)$', '--collector.\1') | list)
+ (['--web.listen-address=' + ansible_host + ':9100'] if node_exporter_bind_tailscale | bool else []) }}
when: ansible_facts["os_family"] == "Debian"
- name: Configure prometheus-node-exporter ARGS (Debian)
ansible.builtin.lineinfile:
path: /etc/default/prometheus-node-exporter
regexp: '^ARGS='
line: 'ARGS="--web.listen-address={{ ansible_host }}:9100"'
line: 'ARGS="{{ _node_exporter_args | join(" ") }}"'
when:
- ansible_facts["os_family"] == "Debian"
- node_exporter_bind_tailscale | bool
- (_node_exporter_args | length > 0)
notify: Restart node-exporter (Debian)
- name: Enable and start node-exporter (Debian)
@ -39,6 +70,7 @@
enabled: true
when: ansible_facts["os_family"] == "Alpine"
# ── FreeBSD ──────────────────────────────────────────────────
- name: Install node_exporter (FreeBSD)
community.general.pkgng:
name: node_exporter