From 0116ec4cc396215eeec0e801b92ec580cffeacbf Mon Sep 17 00:00:00 2001 From: Hermes Agent service account Date: Wed, 27 May 2026 21:39:51 -0500 Subject: [PATCH] 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 --- ansible/playbooks/add_service_route.yml | 27 ++++++++++++------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/ansible/playbooks/add_service_route.yml b/ansible/playbooks/add_service_route.yml index fd08215..76e454e 100644 --- a/ansible/playbooks/add_service_route.yml +++ b/ansible/playbooks/add_service_route.yml @@ -61,20 +61,19 @@ - name: Extract all hostnames from Host() rules ansible.builtin.set_fact: hostnames: >- - {{ - slurped_configs.results - | selectattr('content', 'defined') - | map(attribute='content') - | map('b64decode') - | map('regex_findall', 'Host\\(`([^`]+)`\\)') - | flatten - | map('split', ' || ') - | flatten - | map('regex_replace', '`', '') - | select('match', '.*\\.local\\.mk-labs\\.cloud$') - | unique - | list - }} + {% set hosts = [] -%} + {% for result in slurped_configs.results if result.content is defined -%} + {% set content = result.content | b64decode -%} + {% for match in content | regex_findall('Host\(`([^`]+)`\)') -%} + {% for h in match.split(' || ') -%} + {% set h = h | regex_replace('`', '') | trim -%} + {% if h.endswith('.local.mk-labs.cloud') and h not in hosts -%} + {% set _ = hosts.append(h) -%} + {% endif -%} + {% endfor -%} + {% endfor -%} + {% endfor -%} + {{ hosts | unique | list }} - name: Display hostnames to create ansible.builtin.debug: