From 6f78b5e719b9178b837014fd9fed2839032ab765 Mon Sep 17 00:00:00 2001 From: David Galloway Date: Thu, 19 Feb 2026 19:21:57 -0500 Subject: [PATCH] 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 --- roles/nameserver/templates/forward.j2 | 32 +++++++++++++++++++-------- 1 file changed, 23 insertions(+), 9 deletions(-) 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 %} -- 2.47.3