]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-cm-ansible.git/commitdiff
nameserver: Match A records to reverse[] in named_domains 827/head
authorDavid Galloway <david.galloway@ibm.com>
Fri, 20 Feb 2026 00:21:57 +0000 (19:21 -0500)
committerDavid Galloway <david.galloway@ibm.com>
Fri, 20 Feb 2026 13:40:28 +0000 (08:40 -0500)
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 <david.galloway@ibm.com>
roles/nameserver/templates/forward.j2

index 5f67cdee4b088218d52b96d22f814e9dd5778601..220cfe47f31548340d718ee9b1d3fcc3b0a8c41f 100644 (file)
@@ -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 %}