Capture current Ansible control plane state

Commit the accumulated infrastructure work that was living only in the
working tree: monitoring stack, emergency access/bot, gyro allocator,
grimmory, adguard, backup audit and the OpenCode agent definitions.

Also ignore Python bytecode, local archives and Nix/direnv artifacts.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GTocXkGUUazHdKKd3r9k71
This commit is contained in:
Dmitry
2026-08-26 21:39:28 +03:00
co-authored by Claude Opus 5
parent 4bafa7d09e
commit c676be81ec
126 changed files with 10583 additions and 44 deletions
@@ -0,0 +1,6 @@
---
monitoring_exporter_install_node: true
monitoring_exporter_install_smart: false
monitoring_exporter_textfile_dir: /var/lib/node_exporter/textfile_collector
monitoring_exporter_node_listen_address: 0.0.0.0:9100
monitoring_exporter_smartctl_timer: "*:0/15"
@@ -0,0 +1,9 @@
---
- name: reload systemd
ansible.builtin.systemd:
daemon_reload: true
- name: restart node exporter
ansible.builtin.systemd:
name: prometheus-node-exporter
state: restarted
@@ -0,0 +1,121 @@
---
- name: Install Node Exporter
ansible.builtin.apt:
name: prometheus-node-exporter
state: present
when: monitoring_exporter_install_node
- name: Create Node Exporter textfile directory
ansible.builtin.file:
path: "{{ monitoring_exporter_textfile_dir }}"
state: directory
owner: root
group: root
mode: "0755"
when: monitoring_exporter_install_node
- name: Create Node Exporter systemd override directory
ansible.builtin.file:
path: /etc/systemd/system/prometheus-node-exporter.service.d
state: directory
owner: root
group: root
mode: "0755"
when: monitoring_exporter_install_node
- name: Configure Node Exporter collectors
ansible.builtin.copy:
dest: /etc/systemd/system/prometheus-node-exporter.service.d/override.conf
owner: root
group: root
mode: "0644"
content: |
[Service]
ExecStart=
ExecStart=/usr/bin/prometheus-node-exporter --web.listen-address={{ monitoring_exporter_node_listen_address }} --collector.systemd --collector.textfile.directory={{ monitoring_exporter_textfile_dir }}
when: monitoring_exporter_install_node
notify:
- reload systemd
- restart node exporter
- name: Ensure Node Exporter is enabled and running
ansible.builtin.systemd:
name: prometheus-node-exporter
enabled: true
state: started
when: monitoring_exporter_install_node
- name: Install SMART Exporter dependencies
ansible.builtin.apt:
name:
- jq
- smartmontools
state: present
when: monitoring_exporter_install_smart
- name: Remove obsolete SMART Exporter container unit
ansible.builtin.systemd:
name: homelab-smartctl-exporter
enabled: false
state: stopped
failed_when: false
when: monitoring_exporter_install_smart
- name: Install SMART metric collection script
ansible.builtin.template:
src: smartctl-metrics.sh.j2
dest: /usr/local/sbin/homelab-smartctl-metrics
owner: root
group: root
mode: "0755"
when: monitoring_exporter_install_smart
- name: Install SMART metric collection service
ansible.builtin.copy:
dest: /etc/systemd/system/homelab-smartctl-metrics.service
owner: root
group: root
mode: "0644"
content: |
[Unit]
Description=Publish SMART metrics for Node Exporter
[Service]
Type=oneshot
ExecStart=/usr/local/sbin/homelab-smartctl-metrics
when: monitoring_exporter_install_smart
notify: reload systemd
- name: Install SMART metric collection timer
ansible.builtin.copy:
dest: /etc/systemd/system/homelab-smartctl-metrics.timer
owner: root
group: root
mode: "0644"
content: |
[Unit]
Description=Collect SMART metrics every 15 minutes
[Timer]
OnBootSec=2m
OnUnitActiveSec=15m
Persistent=true
[Install]
WantedBy=multi-user.target
when: monitoring_exporter_install_smart
notify: reload systemd
- name: Enable SMART metric collection timer
ansible.builtin.systemd:
name: homelab-smartctl-metrics.timer
daemon_reload: true
enabled: true
state: started
when: monitoring_exporter_install_smart
- name: Run initial SMART metric collection
ansible.builtin.systemd:
name: homelab-smartctl-metrics.service
state: started
when: monitoring_exporter_install_smart
@@ -0,0 +1,30 @@
#!/bin/sh
# Managed by Ansible. Export SMART health to Node Exporter's textfile collector.
set -eu
METRICS_DIR="{{ monitoring_exporter_textfile_dir }}"
METRICS_FILE="$METRICS_DIR/homelab_smartctl.prom"
METRICS_TMP=$(mktemp "$METRICS_FILE.XXXXXX")
trap 'rm -f "$METRICS_TMP"' EXIT
printf '# HELP homelab_smart_device_healthy SMART overall health (1 healthy, 0 failed)\n' >> "$METRICS_TMP"
printf '# TYPE homelab_smart_device_healthy gauge\n' >> "$METRICS_TMP"
lsblk -dn -o NAME,TYPE | while read -r name type; do
[ "$type" = "disk" ] || continue
device="/dev/$name"
json=$(smartctl -a -j "$device" 2>/dev/null || true)
[ -n "$json" ] || continue
healthy=$(printf '%s' "$json" | jq -r 'if .smart_status.passed == true then 1 else 0 end')
temperature=$(printf '%s' "$json" | jq -r '.temperature.current // .nvme_smart_health_information_log.temperature // empty')
nvme_warning=$(printf '%s' "$json" | jq -r '.nvme_smart_health_information_log.critical_warning // empty')
printf 'homelab_smart_device_healthy{device="%s"} %s\n' "$name" "$healthy" >> "$METRICS_TMP"
[ -z "$temperature" ] || printf 'homelab_smart_temperature_celsius{device="%s"} %s\n' "$name" "$temperature" >> "$METRICS_TMP"
[ -z "$nvme_warning" ] || printf 'homelab_smart_nvme_critical_warning{device="%s"} %s\n' "$name" "$nvme_warning" >> "$METRICS_TMP"
done
chmod 0644 "$METRICS_TMP"
mv "$METRICS_TMP" "$METRICS_FILE"