{# #} {# How many static public addresses/interfaces per node? #} {# #} {% set num_static = (nodes[ansible_hostname].ips | length) - 1 %} {# #} {# Gather all static addresses, sublist per interface #} {# #} {% set static_addrs = [] %} {% for i in range(1, num_static + 1) -%} {{ static_addrs.append([]) }} {%- endfor %} {% for hostname, n in nodes | dictsort %} {% if n.is_ctdb_node %} {% for i in range(1, num_static + 1) -%} {{ static_addrs[i - 1].append(n.ips[i]) }} {%- endfor %} {% endif %} {% endfor %} {# #} {# For each list of static IPs, find interface, print with each IP #} {# #} {% set h = ansible_hostname %} {% for ips in static_addrs %} {% for iface in ansible_interfaces %} {% set ai = 'ansible_%s'|format(iface) %} {% if hostvars[h][ai]['ipv4'] is defined %} {% set ip4 = hostvars[h][ai]['ipv4'] %} {% if ip4['address'] is defined %} {% set aip = ip4['address'] %} {% set netmask = ip4['netmask'] %} {% set prefix = (aip + '/' + netmask) | ipv4('prefix') %} {% if aip in ips %} {% for ip in ips %} {% set ip_int = ip | ipaddr('int') %} {{ (ip_int + 100) | ipaddr('address') }}/{{ prefix }} {{ iface }} {% endfor %} {% endif %} {% endif %} {% endif %} {% if hostvars[h][ai]['ipv6'] is defined %} {% for ip6 in hostvars[h][ai]['ipv6'] %} {% if ip6['address'] is defined %} {% set aip = ip6['address'] %} {% set prefix = ip6['prefix'] %} {% if aip in ips %} {% for ip in ips %} {% set ip_int = ip | ipaddr('int') %} {{ (ip_int + 100) | ipaddr('address') }}/{{ prefix }} {{ iface }} {% endfor %} {% endif %} {% endif %} {% endfor %} {% endif %} {% endfor %} {% endfor %}