{% set net_ip_map = {} %}
{% if ctlplane_ip is defined %}
{% set _ = net_ip_map.__setitem__('ctlplane', ctlplane_ip) %}
{% set _ = net_ip_map.__setitem__('ctlplane_uri', (ctlplane_ip | ipwrap)) %}
{% if ctlplane_subnet is defined %}
{% set _ = net_ip_map.__setitem__('ctlplane_subnet', ctlplane_ip ~ '/' ~ ctlplane_subnet_cidr) %}
{% endif %}
{% endif %}
{% if enabled_networks is defined and enabled_networks %}
{% for network in enabled_networks %}
{%   if network_cidrs is defined and network_cidrs and ((network ~ '_cidr') in network_cidrs) %}
{%     set _ = net_ip_map.__setitem__(networks[network]['name'], (hostvars[inventory_hostname][networks[network]['name'] ~ '_ip'])) %}
{%     set _ = net_ip_map.__setitem__((networks[network]['name'] ~ '_subnet'), (hostvars[inventory_hostname][networks[network]['name'] ~ '_ip'] ~ '/' ~ network_cidrs[network ~ '_cidr'])) %}
{%     set _ = net_ip_map.__setitem__((networks[network]['name'] ~ '_uri'), (hostvars[inventory_hostname][networks[network]['name'] ~ '_ip'] | ipwrap)) %}
{%   else %}
{#     just add empty entries for this network if it doesn't apply to this role. matches previous behavior from Heat #}
{%     set _ = net_ip_map.__setitem__(networks[network]['name'], "") %}
{%     set _ = net_ip_map.__setitem__((networks[network]['name'] ~ '_subnet'), "") %}
{%     set _ = net_ip_map.__setitem__((networks[network]['name'] ~ '_uri'), "") %}
{%   endif %}
{% endfor %}
{% endif %}
{% if hieradata_localhost_address is undefined %}
{%   set hieradata_localhost_address = ('ipv6' in (ansible_lo | default({}))) | ternary('localhost', '127.0.0.1') %}
{% endif %}
{% set _ = net_ip_map.__setitem__('localhost_address', hieradata_localhost_address) %}
{# RENDER #}
{{ net_ip_map | to_nice_json }}
