]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-cm-ansible.git/commitdiff
nameserver: Support multiple ipvars 800/head
authorDavid Galloway <david.galloway@ibm.com>
Tue, 9 Dec 2025 00:53:19 +0000 (19:53 -0500)
committerDavid Galloway <david.galloway@ibm.com>
Tue, 9 Dec 2025 00:57:10 +0000 (19:57 -0500)
Signed-off-by: David Galloway <david.galloway@ibm.com>
roles/nameserver/README.rst
roles/nameserver/templates/forward.j2
roles/nameserver/templates/reverse.j2

index 85ac3d37a307b80f4e15ad562bda385bb113a974..56209b5766922f24ba9ddd419c8be5ff63e6f2c0 100644 (file)
@@ -103,8 +103,8 @@ The ``named_domains`` dictionary is the bread and butter of creating zone files.
 ``forward``
   The domain of the forward lookup zone for each domain (key)
 
-``ipvar``
-  The variable assigned to a system in the Ansible inventory.  This allows systems to have multiple IPs assigned for a front and ipmi network, for example.  See **Inventory Example** below.
+``ipvar`` OR ``ipvars[]``
+  The variable(s) assigned to a system in the Ansible inventory.  This allows systems to have multiple IPs assigned for a front and ipmi network, for example.  See **Inventory Example** below.
 
 ``dynamic``
   Specifies whether the parent zone/domain should allow Dynamic DNS records.  See **Dynamic DNS** below for more information.
@@ -130,7 +130,9 @@ The ``named_domains`` dictionary is the bread and butter of creating zone files.
           - www                 IN      TXT     "my www host"
           - ns1.private         IN      A       192.168.0.1
       private.example.com:
-        ipvar: ip
+        ipvars:
+          - ip
+          - if_25Gb_ip
         dynamic: true
         ddns_hostname_prefixes:
           - dyn
index 5ce8c2e728a5d7d74cbf6e047b79734c279774d8..5f67cdee4b088218d52b96d22f814e9dd5778601 100644 (file)
@@ -1,7 +1,13 @@
 {% set domain = item.key %}
-{% if item.value.ipvar is defined and item.value.ipvar.0 is defined %}
-{% set ipvar = item.value.ipvar %}
+
+{# Normalize ipvars: prefer item.value.ipvars (list), fallback to single ipvar #}
+{% set ipvars = [] %}
+{% if item.value.ipvars is defined %}
+  {% set ipvars = item.value.ipvars %}
+{% elif item.value.ipvar is defined %}
+  {% set ipvars = [ item.value.ipvar ] %}
 {% endif %}
+
 ;
 ; {{ ansible_managed }}
 ;
@@ -26,11 +32,13 @@ $ORIGIN {{ domain }}.
 {% endfor %}
 {% endif %}
 
-{% if item.value.ipvar is defined and item.value.ipvar.0 is defined %}
-{% for host in groups['all'] %}
-{% if hostvars[host][ipvar] is defined %}
-{% set ipaddr = hostvars[host][ipvar] %}
-{{ hostvars[host]['inventory_hostname_short'] }}                       IN      A       {{ hostvars[host][ipvar] }}
-{% endif %}
-{% endfor %}
+{# 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 %}
 {% endif %}
index 6d6e82a052ac6415a8f7c344fed54d71055e74f8..3f76e581c5594fd3c0e913f879b38cfe8b78114a 100644 (file)
@@ -1,6 +1,14 @@
 {% set zone = item.1 %}
 {% set domain = item.0.forward %}
-{% set ipvar = item.0.ipvar %}
+
+{# Normalize ipvars from item.0: prefer ipvars list, fall back to ipvar #}
+{% set ipvars = [] %}
+{% if item.0.ipvars is defined and item.0.ipvars %}
+  {% set ipvars = item.0.ipvars %}
+{% elif item.0.ipvar is defined and item.0.ipvar %}
+  {% set ipvars = [ item.0.ipvar ] %}
+{% endif %}
+
 ;
 ; {{ ansible_managed }}
 ;
@@ -19,12 +27,17 @@ $TTL {{ named_conf_soa_ttl }}
 
 ; Reverse zone {{ zone }} belongs to forward zone {{ domain }}
 
-{% for host in groups['all'] %}
-{% if hostvars[host][ipvar] is defined %}
-{% set octet1,octet2,octet3,octet4 = hostvars[host][ipvar].split('.') %}
-{% set cutip = octet1 + '.' + octet2 + '.' + octet3 %}
-{% if cutip == zone %}
-{{ octet4 }}           IN      PTR     {{ hostvars[host]['inventory_hostname_short'] }}.{{ domain }}.
+{% if ipvars | length > 0 %}
+{%   for host in groups['all'] %}
+{%     for ipvar in ipvars %}
+{%       if hostvars[host][ipvar] is defined %}
+{%         set octet1,octet2,octet3,octet4 = hostvars[host][ipvar].split('.') %}
+{%         set cutip = octet1 + '.' + octet2 + '.' + octet3 %}
+{%         if cutip == zone %}
+{%           set short = hostvars[host].inventory_hostname_short | default(host) %}
+{{ octet4 }}    IN      PTR     {{ short }}.{{ domain }}.
+{%         endif %}
+{%       endif %}
+{%     endfor %}
+{%   endfor %}
 {% endif %}
-{% endif %}
-{% endfor %}