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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user