Files
2026-02-21 16:54:18 +01:00

81 lines
2.0 KiB
YAML

---
- name: Create metrics exporter directory
file:
path: /usr/lib/wg-lab-exporter
state: directory
mode: '0755'
- name: Deploy metrics exporter script
template:
src: metrics-exporter.sh.j2
dest: /usr/lib/wg-lab-exporter/exporter.sh
mode: '0755'
- name: Create exporter configuration
template:
src: exporter-config.j2
dest: /etc/wg-lab-exporter.conf
mode: '0644'
- name: Create uhttpd configuration for metrics endpoint
blockinfile:
path: /etc/uhttpd.conf
create: yes
marker: "# {mark} ANSIBLE MANAGED - Metrics Exporter"
block: |
config uhttpd 'metrics'
list listen_http '0.0.0.0:9586'
option home '/www-metrics'
option cgi_prefix '/metrics'
option script_timeout '10'
option network_timeout '30'
option tcp_keepalive '1'
- name: Create metrics web directory
file:
path: /www-metrics/metrics
state: directory
mode: '0755'
- name: Create CGI wrapper for metrics
copy:
dest: /www-metrics/metrics/index.cgi
mode: '0755'
content: |
#!/bin/sh
echo "Content-Type: text/plain"
echo ""
/usr/lib/wg-lab-exporter/exporter.sh
- name: Create cron job for metrics collection (fallback)
cron:
name: "WireGuard Lab Metrics Collection"
minute: "*/5"
job: "/usr/lib/wg-lab-exporter/exporter.sh > /tmp/wg-lab-metrics.txt"
user: root
- name: Restart uhttpd
shell: /etc/init.d/uhttpd restart
changed_when: true
- name: Test metrics endpoint
uri:
url: "http://localhost:9586/metrics/"
timeout: 5
register: metrics_test
ignore_errors: yes
changed_when: false
- name: Display metrics test result
debug:
msg: "Metrics endpoint {{ 'OK' if metrics_test.status == 200 else 'FAILED' }}"
- name: Show sample metrics output
shell: /usr/lib/wg-lab-exporter/exporter.sh | head -20
register: metrics_sample
changed_when: false
- name: Display sample metrics
debug:
var: metrics_sample.stdout_lines