From: David Galloway Date: Fri, 20 Feb 2026 00:21:57 +0000 (-0500) Subject: nameserver: Match A records to reverse[] in named_domains X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6f78b5e719b9178b837014fd9fed2839032ab765;p=ceph-cm-ansible.git nameserver: Match A records to reverse[] in named_domains This will let multiple subnets/domains use the same ipvar For example, bath and infra-compute can both have a if_25Gb_ip ``` bath14.front.sepia.ceph.com if_25Gb_ip=10.20.192.44 infra-compute-01.os.sepia.ceph.com if_25Gb_1_ip=172.16.53.11 front.sepia.ceph.com: forward: front.sepia.ceph.com ipvars: - ip - if_25Gb_1_ip dynamic: true ddns_hostname_prefixes: - ovh reverse: - 10.20.192 - 10.20.193 os.sepia.ceph.com: forward: os.sepia.ceph.com ipvar: if_25Gb_1_ip dynamic: false reverse: - 172.16.53 - 172.16.54 ``` `bath14 IN A` will get written to front.sepia.ceph.com `infra-compute-01 IN A` will get written to os.sepia.ceph.com Signed-off-by: David Galloway --- diff --git a/roles/nameserver/templates/forward.j2 b/roles/nameserver/templates/forward.j2 index 5f67cdee..220cfe47 100644 --- a/roles/nameserver/templates/forward.j2 +++ b/roles/nameserver/templates/forward.j2 @@ -32,13 +32,27 @@ $ORIGIN {{ domain }}. {% endfor %} {% endif %} -{# Emit A records for each host and each ipvar #} -{% if ipvars | length > 0 %} -{% for host in groups['all'] %} -{% for ipvar in ipvars %} -{% if hostvars[host][ipvar] is defined %} -{{ hostvars[host]['inventory_hostname_short'] }} IN A {{ hostvars[host][ipvar] }} -{% endif %} -{% endfor %} -{% endfor %} +{% set reverse_prefixes = item.value.reverse | default([]) %} + +{%- if ipvars | length > 0 %} +{%- for host in groups['all'] %} +{%- for ipvar in ipvars %} +{%- set ip = hostvars[host].get(ipvar) %} +{%- if ip %} + +{# Emit A records for each host/ipvar ONLY if the IP matches one of item.value.reverse prefixes #} +{%- set ns = namespace(ok=false) %} +{%- for rev in reverse_prefixes %} +{%- if ip == rev or ip.startswith(rev ~ '.') %} +{%- set ns.ok = true %} +{%- endif %} +{%- endfor %} + +{%- if ns.ok %} +{{ "%-40s %-6s %-6s %s" | format(hostvars[host]['inventory_hostname_short'], "IN", "A", ip) }} +{% endif %} + +{% endif %} +{% endfor %} +{% endfor %} {% endif %}