fix(dns): improve hostname extraction in add_service_route.yml

- Use explicit Jinja2 loop for more reliable parsing of Host() rules
- Handles multi-host router definitions correctly
This commit is contained in:
Hermes Agent service account
2026-05-27 21:39:51 -05:00
parent f962d0a6d7
commit 0116ec4cc3

View File

@@ -61,20 +61,19 @@
- name: Extract all hostnames from Host() rules - name: Extract all hostnames from Host() rules
ansible.builtin.set_fact: ansible.builtin.set_fact:
hostnames: >- hostnames: >-
{{ {% set hosts = [] -%}
slurped_configs.results {% for result in slurped_configs.results if result.content is defined -%}
| selectattr('content', 'defined') {% set content = result.content | b64decode -%}
| map(attribute='content') {% for match in content | regex_findall('Host\(`([^`]+)`\)') -%}
| map('b64decode') {% for h in match.split(' || ') -%}
| map('regex_findall', 'Host\\(`([^`]+)`\\)') {% set h = h | regex_replace('`', '') | trim -%}
| flatten {% if h.endswith('.local.mk-labs.cloud') and h not in hosts -%}
| map('split', ' || ') {% set _ = hosts.append(h) -%}
| flatten {% endif -%}
| map('regex_replace', '`', '') {% endfor -%}
| select('match', '.*\\.local\\.mk-labs\\.cloud$') {% endfor -%}
| unique {% endfor -%}
| list {{ hosts | unique | list }}
}}
- name: Display hostnames to create - name: Display hostnames to create
ansible.builtin.debug: ansible.builtin.debug: