host_exporters: host_exporters_listen_address binds the node exporter to one address for hosts without host firewall
This commit is contained in:
@@ -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
|
# Adds prometheus-smartctl-exporter (trixie-backports) next to the node exporter
|
||||||
# on hosts with physical disks.
|
# on hosts with physical disks.
|
||||||
host_exporters_smart: false
|
host_exporters_smart: false
|
||||||
|
|||||||
@@ -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.
|
# Its recommends (smartmontools, nvme-cli, ipmitool) start units that fail on hosts without such hardware.
|
||||||
- name: Install the node exporter
|
- name: Install the node exporter
|
||||||
ansible.builtin.apt:
|
ansible.builtin.apt:
|
||||||
@@ -7,11 +8,44 @@
|
|||||||
install_recommends: false
|
install_recommends: false
|
||||||
state: present
|
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
|
- name: Enable the node exporter
|
||||||
ansible.builtin.systemd:
|
ansible.builtin.systemd:
|
||||||
name: prometheus-node-exporter
|
name: prometheus-node-exporter
|
||||||
enabled: true
|
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.
|
# Check mode does not install the package.
|
||||||
ignore_errors: "{{ ansible_check_mode }}"
|
ignore_errors: "{{ ansible_check_mode }}"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user