Files
Ansible-Bootstrap/roles/virtualization/templates/cloud-network-config.yml.j2
Sandwich 8071a7c56c feat(network): make interfaces[] canonical, normalize flat fields as AWX compat
Flat network fields (bridge, ip, prefix, gateway, vlan) are now converted
into a single-entry interfaces[] list during normalization. All virtualization
tasks (proxmox, vmware, libvirt, xen) and configuration (NM, Alpine, Void)
now consume system_cfg.network.interfaces exclusively for multi-NIC support.

Also fixes: user.key -> user.keys in system_cfg output, strict list-only DNS
in example inventories, removes legacy single-MAC virtualization_mac_address
default.
2026-02-12 22:17:02 +01:00

46 lines
1.3 KiB
Django/Jinja

network:
version: 2
ethernets:
{% set dns_list = system_cfg.network.dns.servers | default([]) %}
{% set search_list = system_cfg.network.dns.search | default([]) %}
{% for iface in system_cfg.network.interfaces %}
{% set iface_mac = '52:54:00' | community.general.random_mac(seed=hostname if loop.index0 == 0 else hostname ~ '-nic' ~ loop.index0) %}
{% set has_static = (iface.ip | default('') | string | length) > 0 %}
id{{ loop.index0 }}:
match:
macaddress: "{{ iface_mac }}"
{% if has_static %}
addresses:
- "{{ iface.ip }}/{{ iface.prefix }}"
{% if iface.gateway | default('') | string | length %}
gateway4: "{{ iface.gateway }}"
{% endif %}
{% else %}
dhcp4: true
{% if loop.index0 == 0 and (dns_list | length or search_list | length) %}
dhcp4-overrides:
{% if dns_list | length %}
use-dns: false
{% endif %}
{% if search_list | length %}
use-domains: false
{% endif %}
{% endif %}
{% endif %}
{% if loop.index0 == 0 and (dns_list or search_list) %}
nameservers:
{% if dns_list %}
addresses:
{% for dns in dns_list %}
- "{{ dns }}"
{% endfor %}
{% endif %}
{% if search_list %}
search:
{% for search in search_list %}
- "{{ search }}"
{% endfor %}
{% endif %}
{% endif %}
{% endfor %}