host_exporters: host_exporters_listen_address binds the node exporter to one address for hosts without host firewall

This commit is contained in:
2026-10-26 15:45:34 +00:00
parent 03fc22daf7
commit 61db0ed55e
2 changed files with 40 additions and 2 deletions
+4
View File
@@ -1,4 +1,8 @@
---
# Address the node exporter binds to; empty = all addresses. For hosts without host_firewall: the NetBird
# address keeps the port off the LAN, and the mesh ACL decides who reaches it.
host_exporters_listen_address: ""
# Adds prometheus-smartctl-exporter (trixie-backports) next to the node exporter
# on hosts with physical disks.
host_exporters_smart: false
+36 -2
View File
@@ -1,5 +1,6 @@
---
# Both exporters listen on all addresses; host_firewall limits who reaches them.
# Both exporters listen on all addresses (the node exporter on host_exporters_listen_address if set); host_firewall
# limits who reaches them.
# Its recommends (smartmontools, nvme-cli, ipmitool) start units that fail on hosts without such hardware.
- name: Install the node exporter
ansible.builtin.apt:
@@ -7,11 +8,44 @@
install_recommends: false
state: present
- name: Bind the node exporter to one address
ansible.builtin.lineinfile:
path: /etc/default/prometheus-node-exporter
regexp: '^ARGS='
line: 'ARGS="--web.listen-address={{ host_exporters_listen_address }}:9100"'
when: host_exporters_listen_address | length > 0
register: host_exporters_listen
# Check mode does not install the package.
ignore_errors: "{{ ansible_check_mode }}"
- name: Create the node exporter unit drop-in directory
ansible.builtin.file:
path: /etc/systemd/system/prometheus-node-exporter.service.d
state: directory
mode: "0755"
when: host_exporters_listen_address | length > 0
# The NetBird address exists only after the daemon is up, and a failed bind must not exhaust the start limit.
- name: Start the bound node exporter after NetBird and retry
ansible.builtin.copy:
dest: /etc/systemd/system/prometheus-node-exporter.service.d/listen-address.conf
mode: "0644"
content: |
[Unit]
After=netbird.service
StartLimitIntervalSec=0
[Service]
RestartSec=5s
when: host_exporters_listen_address | length > 0
register: host_exporters_listen_unit
- name: Enable the node exporter
ansible.builtin.systemd:
name: prometheus-node-exporter
enabled: true
state: started
state: "{{ 'restarted' if (host_exporters_listen.changed or host_exporters_listen_unit.changed) else 'started' }}"
daemon_reload: "{{ host_exporters_listen_unit.changed }}"
# Check mode does not install the package.
ignore_errors: "{{ ansible_check_mode }}"