feat: add node_exporter role and integrate into site playbook
OpenVPN Ansible / Ansible Lint (push) Failing after 14s
OpenVPN Ansible / Ansible Syntax Check (push) Failing after 14s
OpenVPN Ansible / Deploy VPN Networking and OpenVPN (push) Skipped
OpenVPN Ansible / Generate SBOM (push) Skipped
OpenVPN Ansible / Scan SBOM with Trivy (push) Skipped
OpenVPN Ansible / Ansible Lint (push) Failing after 14s
OpenVPN Ansible / Ansible Syntax Check (push) Failing after 14s
OpenVPN Ansible / Deploy VPN Networking and OpenVPN (push) Skipped
OpenVPN Ansible / Generate SBOM (push) Skipped
OpenVPN Ansible / Scan SBOM with Trivy (push) Skipped
This commit is contained in:
@@ -89,3 +89,21 @@ Also connect to the existing FreeRADIUS NodePort endpoint using its configured
|
|||||||
address and port. DNS and NodePort checks require live network access. The
|
address and port. DNS and NodePort checks require live network access. The
|
||||||
inventory gateway IP/interface values are taken from the supplied task; verify
|
inventory gateway IP/interface values are taken from the supplied task; verify
|
||||||
them against the live Hetzner VM before applying.
|
them against the live Hetzner VM before applying.
|
||||||
|
|
||||||
|
## Monitoring exporter
|
||||||
|
|
||||||
|
Run `playbooks/monitoring-exporter.yml` for the VPN nodes and NAT gateway.
|
||||||
|
Set `monitoring_vm_ip` in `inventories/prod/group_vars/all.yml` to the monitoring
|
||||||
|
VM's address on the `10.100.0.x` private network. It is the only allowed source
|
||||||
|
to TCP port 9100. The identical `node_exporter` role defaults to port 9100,
|
||||||
|
binds to `private_ip` then `keepalived_src_ip` then `ansible_host`, and uses
|
||||||
|
`monitoring_vm_ip` as its firewall source. It creates the root-owned,
|
||||||
|
world-readable `/var/lib/node_exporter/textfile` directory and enables
|
||||||
|
systemd, conntrack, filesystem, netdev, textfile, time, and timex collectors;
|
||||||
|
`node_exporter_systemd_unit_filter` restricts unit metrics.
|
||||||
|
|
||||||
|
On the NAT gateway, `node_exporter_port` defaults to 9100 and
|
||||||
|
`node_exporter_allowed_source` uses `monitoring_vm_ip`. Both the
|
||||||
|
ACCEPT for that source and DROP for all other sources on the port are written
|
||||||
|
into `ensure-nat-gateway-firewall.j2`, so the gateway firewall persistence
|
||||||
|
service owns them.
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
timezone: Europe/Berlin
|
timezone: Europe/Berlin
|
||||||
|
# Required: monitoring VM private address on the 10.100.0.x private network.
|
||||||
|
monitoring_vm_ip: "10.100.0.30"
|
||||||
common_packages:
|
common_packages:
|
||||||
- vim
|
- vim
|
||||||
- curl
|
- curl
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
---
|
||||||
|
- name: Configure node exporter on VPN nodes
|
||||||
|
hosts: vpn_nodes
|
||||||
|
become: true
|
||||||
|
roles:
|
||||||
|
- role: node_exporter
|
||||||
|
tags: [monitoring]
|
||||||
|
|
||||||
|
- name: Configure node exporter and firewall on NAT gateway
|
||||||
|
hosts: nat_gateways
|
||||||
|
become: true
|
||||||
|
roles:
|
||||||
|
- role: nat_gateway
|
||||||
|
- role: node_exporter
|
||||||
|
vars:
|
||||||
|
node_exporter_manage_firewall: false
|
||||||
|
tags: [monitoring]
|
||||||
@@ -3,3 +3,6 @@ nat_gateway_private_cidr: 10.100.0.0/16
|
|||||||
nat_gateway_private_interface: enp7s0
|
nat_gateway_private_interface: enp7s0
|
||||||
nat_gateway_public_interface: eth0
|
nat_gateway_public_interface: eth0
|
||||||
nat_gateway_firewall_script: /usr/local/sbin/ensure-nat-gateway-firewall
|
nat_gateway_firewall_script: /usr/local/sbin/ensure-nat-gateway-firewall
|
||||||
|
# Exporter firewall accepts this private source and drops all others on its port.
|
||||||
|
node_exporter_port: 9100
|
||||||
|
node_exporter_allowed_source: "{{ monitoring_vm_ip }}"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
- name: Install iptables tools
|
- name: Install iptables tools
|
||||||
ansible.builtin.apt:
|
ansible.builtin.apt:
|
||||||
name: iptables
|
name: [iptables, prometheus-node-exporter]
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
- name: Install idempotent NAT firewall restore script
|
- name: Install idempotent NAT firewall restore script
|
||||||
@@ -45,6 +45,14 @@
|
|||||||
sysctl_file: /etc/sysctl.d/99-nat-gateway.conf
|
sysctl_file: /etc/sysctl.d/99-nat-gateway.conf
|
||||||
reload: true
|
reload: true
|
||||||
|
|
||||||
|
- name: Create node exporter textfile directory
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: /var/lib/node_exporter/textfile
|
||||||
|
state: directory
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0755"
|
||||||
|
|
||||||
- name: Allow private subnet outbound through public interface
|
- name: Allow private subnet outbound through public interface
|
||||||
ansible.builtin.iptables:
|
ansible.builtin.iptables:
|
||||||
table: nat
|
table: nat
|
||||||
|
|||||||
@@ -9,3 +9,9 @@ iptables -C FORWARD -i {{ nat_gateway_private_interface }} -o {{ nat_gateway_pub
|
|||||||
|
|
||||||
iptables -C FORWARD -i {{ nat_gateway_public_interface }} -o {{ nat_gateway_private_interface }} -d {{ nat_gateway_private_cidr }} -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT 2>/dev/null || \
|
iptables -C FORWARD -i {{ nat_gateway_public_interface }} -o {{ nat_gateway_private_interface }} -d {{ nat_gateway_private_cidr }} -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT 2>/dev/null || \
|
||||||
iptables -A FORWARD -i {{ nat_gateway_public_interface }} -o {{ nat_gateway_private_interface }} -d {{ nat_gateway_private_cidr }} -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
|
iptables -A FORWARD -i {{ nat_gateway_public_interface }} -o {{ nat_gateway_private_interface }} -d {{ nat_gateway_private_cidr }} -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
|
||||||
|
|
||||||
|
iptables -C INPUT -p tcp -s {{ node_exporter_allowed_source }} --dport {{ node_exporter_port }} -j ACCEPT 2>/dev/null || \
|
||||||
|
iptables -I INPUT 1 -p tcp -s {{ node_exporter_allowed_source }} --dport {{ node_exporter_port }} -j ACCEPT
|
||||||
|
|
||||||
|
iptables -C INPUT -p tcp --dport {{ node_exporter_port }} -j DROP 2>/dev/null || \
|
||||||
|
iptables -I INPUT 2 -p tcp --dport {{ node_exporter_port }} -j DROP
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
---
|
||||||
|
# Bind to private_ip, then the LB keepalived source IP, and use public ansible_host
|
||||||
|
# only if neither private address is configured.
|
||||||
|
node_exporter_listen_address: "{{ private_ip | default(keepalived_src_ip | default(ansible_host)) }}"
|
||||||
|
# TCP listener port for node_exporter.
|
||||||
|
node_exporter_port: 9100
|
||||||
|
# Required: set to monitoring_vm_ip in inventory/group_vars.
|
||||||
|
node_exporter_allowed_source: "{{ monitoring_vm_ip }}"
|
||||||
|
# Root-owned, world-readable textfile collector directory.
|
||||||
|
node_exporter_textfile_dir: /var/lib/node_exporter/textfile
|
||||||
|
# Restrict systemd collector output to relevant service units.
|
||||||
|
node_exporter_systemd_unit_filter: "^(openvpn.*|squid@.*|keepalived.service|nat-gateway-firewall.service)$"
|
||||||
|
# Collect systemd, connection tracking, filesystem, network, textfile, time, and timex metrics.
|
||||||
|
node_exporter_collectors:
|
||||||
|
- systemd
|
||||||
|
- conntrack
|
||||||
|
- filesystem
|
||||||
|
- netdev
|
||||||
|
- textfile
|
||||||
|
- time
|
||||||
|
- timex
|
||||||
|
# Use iptables allow/drop rules locally; NAT gateway disables this because its
|
||||||
|
# firewall script owns those rules.
|
||||||
|
node_exporter_manage_firewall: true
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
- name: Restart node exporter
|
||||||
|
ansible.builtin.systemd:
|
||||||
|
name: prometheus-node-exporter
|
||||||
|
state: restarted
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
---
|
||||||
|
- name: Require the monitoring VM private source address
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- monitoring_vm_ip is defined
|
||||||
|
- monitoring_vm_ip | length > 0
|
||||||
|
fail_msg: Set monitoring_vm_ip to the monitoring VM's 10.100.0.x address.
|
||||||
|
tags: [monitoring]
|
||||||
|
|
||||||
|
- name: Install node exporter package
|
||||||
|
ansible.builtin.apt:
|
||||||
|
name: prometheus-node-exporter
|
||||||
|
state: present
|
||||||
|
update_cache: true
|
||||||
|
cache_valid_time: 3600
|
||||||
|
tags: [monitoring]
|
||||||
|
|
||||||
|
- name: Install iptables persistence packages
|
||||||
|
ansible.builtin.apt:
|
||||||
|
name: [iptables, iptables-persistent]
|
||||||
|
state: present
|
||||||
|
update_cache: true
|
||||||
|
cache_valid_time: 3600
|
||||||
|
environment:
|
||||||
|
DEBIAN_FRONTEND: noninteractive
|
||||||
|
tags: [monitoring]
|
||||||
|
|
||||||
|
- name: Create node exporter textfile directory
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ node_exporter_textfile_dir }}"
|
||||||
|
state: directory
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0755"
|
||||||
|
tags: [monitoring]
|
||||||
|
|
||||||
|
- name: Configure node exporter arguments
|
||||||
|
ansible.builtin.copy:
|
||||||
|
dest: /etc/default/prometheus-node-exporter
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0644"
|
||||||
|
content: >-
|
||||||
|
ARGS="--web.listen-address={{ node_exporter_listen_address }}:{{ node_exporter_port }}
|
||||||
|
{% for collector in node_exporter_collectors %}--collector.{{ collector }} {% endfor %}
|
||||||
|
--collector.systemd.unit-include={{ node_exporter_systemd_unit_filter }}
|
||||||
|
--collector.textfile.directory={{ node_exporter_textfile_dir }}"
|
||||||
|
notify: Restart node exporter
|
||||||
|
tags: [monitoring]
|
||||||
|
|
||||||
|
- name: Allow monitoring VM to access node exporter
|
||||||
|
ansible.builtin.iptables:
|
||||||
|
chain: INPUT
|
||||||
|
protocol: tcp
|
||||||
|
destination_port: "{{ node_exporter_port }}"
|
||||||
|
source: "{{ node_exporter_allowed_source }}"
|
||||||
|
jump: ACCEPT
|
||||||
|
comment: Allow monitoring VM node exporter
|
||||||
|
action: insert
|
||||||
|
rule_num: 1
|
||||||
|
register: node_exporter_allow_rule
|
||||||
|
tags: [monitoring]
|
||||||
|
when: node_exporter_manage_firewall
|
||||||
|
|
||||||
|
- name: Drop other node exporter access
|
||||||
|
ansible.builtin.iptables:
|
||||||
|
chain: INPUT
|
||||||
|
protocol: tcp
|
||||||
|
destination_port: "{{ node_exporter_port }}"
|
||||||
|
jump: DROP
|
||||||
|
comment: Drop other node exporter access
|
||||||
|
action: insert
|
||||||
|
rule_num: 2
|
||||||
|
register: node_exporter_drop_rule
|
||||||
|
tags: [monitoring]
|
||||||
|
when: node_exporter_manage_firewall
|
||||||
|
|
||||||
|
- name: Persist node exporter firewall rules
|
||||||
|
ansible.builtin.command: netfilter-persistent save
|
||||||
|
when:
|
||||||
|
- node_exporter_manage_firewall
|
||||||
|
- node_exporter_allow_rule is changed or node_exporter_drop_rule is changed
|
||||||
|
changed_when: true
|
||||||
|
tags: [monitoring]
|
||||||
|
|
||||||
|
- name: Enable and start node exporter
|
||||||
|
ansible.builtin.systemd:
|
||||||
|
name: prometheus-node-exporter
|
||||||
|
state: started
|
||||||
|
enabled: true
|
||||||
|
tags: [monitoring]
|
||||||
Reference in New Issue
Block a user