/
/
/
1---
2# ========================================
3# SERVICE COORDINATION AND VALIDATION
4# ========================================
5# Manages service startup order, health checks, and integration
6# Ensures proper service dependencies and coordination
7
8- name: "Determine service startup order"
9 ansible.builtin.set_fact:
10 service_startup_order: |
11 {% set services = [] %}
12 {% if connectivity_unbound_enabled | default(false) %}
13 {% set services = services + ['unbound'] %}
14 {% endif %}
15 {% if connectivity_pihole_enabled | default(false) %}
16 {% set services = services + ['pihole'] %}
17 {% endif %}
18 {% if connectivity_nginx_proxy_enabled | default(false) %}
19 {% set services = services + ['nginx-proxy'] %}
20 {% endif %}
21 {% if connectivity_wireguard_enabled | default(false) %}
22 {% set services = services + ['wireguard'] %}
23 {% endif %}
24 {{ services }}
25 tags: [services, coordination]
26
27- name: "Wait for DNS services to be ready"
28 block:
29 - name: "Wait for Unbound recursive DNS"
30 ansible.builtin.wait_for:
31 port: "{{ connectivity_unbound_port | default(5335) }}"
32 host: 127.0.0.1
33 delay: 5
34 timeout: 60
35 when: connectivity_unbound_enabled | default(false)
36
37 - name: "Wait for Pi-hole DNS"
38 ansible.builtin.wait_for:
39 port: "{{ connectivity_pihole_dns_port | default(53) }}"
40 host: 127.0.0.1
41 delay: 10
42 timeout: 90
43 when: connectivity_pihole_enabled | default(false)
44
45 when: connectivity_dns_stack_enabled | default(false)
46 tags: [services, dns, coordination]
47
48- name: "Wait for proxy services to be ready"
49 block:
50 - name: "Wait for Nginx Proxy Manager"
51 ansible.builtin.wait_for:
52 port: "{{ connectivity_nginx_proxy_admin_port | default(81) }}"
53 host: 127.0.0.1
54 delay: 10
55 timeout: 60
56 when: connectivity_nginx_proxy_enabled | default(false)
57
58 tags: [services, proxy, coordination]
59
60- name: "Wait for VPN services to be ready"
61 block:
62 - name: "Wait for WireGuard"
63 ansible.builtin.wait_for:
64 port: "{{ connectivity_wireguard_port | default(51820) }}"
65 host: 127.0.0.1
66 delay: 5
67 timeout: 30
68 when: connectivity_wireguard_enabled | default(false)
69
70 tags: [services, vpn, coordination]
71
72- name: "Verify all connectivity services are running"
73 ansible.builtin.command: docker ps --filter "label=com.connectivity.service" --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
74 register: connectivity_services_status
75 changed_when: false
76 failed_when: false
77 tags: [services, verify]
78
79- name: "Perform service health checks"
80 block:
81 - name: "Test DNS resolution through Pi-hole"
82 ansible.builtin.command: "dig @127.0.0.1 google.com +short"
83 register: dns_health_check
84 changed_when: false
85 ignore_errors: yes
86 when: connectivity_pihole_enabled | default(false)
87
88 - name: "Test Nginx Proxy Manager health"
89 ansible.builtin.uri:
90 url: "http://127.0.0.1:{{ connectivity_nginx_proxy_admin_port | default(81) }}"
91 method: GET
92 status_code: [200, 302]
93 timeout: 10
94 register: nginx_health_check
95 ignore_errors: yes
96 when: connectivity_nginx_proxy_enabled | default(false)
97
98 - name: "Test WireGuard health"
99 ansible.builtin.command: "wg show"
100 register: wireguard_health_check
101 changed_when: false
102 ignore_errors: yes
103 when: connectivity_wireguard_enabled | default(false)
104
105 tags: [services, health-check]
106
107- name: "Display connectivity services status"
108 ansible.builtin.debug:
109 msg: |
110 ð Connectivity Services Status
111
112 Running Services:
113 {% if connectivity_services_status.stdout_lines | length > 1 %}
114 {% for line in connectivity_services_status.stdout_lines[1:] %}
115 - {{ line }}
116 {% endfor %}
117 {% else %}
118 - No connectivity services found with label
119 {% endif %}
120
121 Health Checks:
122 {% if connectivity_pihole_enabled | default(false) %}
123 - DNS Resolution: {{ 'â
OK' if dns_health_check.rc == 0 else 'â Failed' }}
124 {% endif %}
125 {% if connectivity_nginx_proxy_enabled | default(false) %}
126 - Nginx Proxy: {{ 'â
OK' if nginx_health_check.status == 200 else 'â Failed' }}
127 {% endif %}
128 {% if connectivity_wireguard_enabled | default(false) %}
129 - WireGuard: {{ 'â
OK' if wireguard_health_check.rc == 0 else 'â Failed' }}
130 {% endif %}
131
132 Service Startup Order:
133 {% for service in service_startup_order | default([]) %}
134 {{ loop.index }}. {{ service }}
135 {% endfor %}
136 when: connectivity_services_status is defined
137 tags: [services, info]