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 %} routes: - to: default via: "{{ 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 %}