feat(network): make interfaces[] canonical, normalize flat fields as AWX compat

This commit is contained in:
2026-02-12 22:17:02 +01:00
parent 5108e46a4c
commit 66057bc9b2
17 changed files with 222 additions and 159 deletions

View File

@@ -1,21 +1,23 @@
network:
version: 2
ethernets:
id0:
match:
macaddress: "{{ virtualization_mac_address }}"
{% set has_static = system_cfg.network.ip is defined and system_cfg.network.ip | string | length %}
{% 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:
- "{{ system_cfg.network.ip }}/{{ system_cfg.network.prefix }}"
{% if system_cfg.network.gateway is defined and system_cfg.network.gateway | string | length %}
gateway4: "{{ system_cfg.network.gateway }}"
- "{{ iface.ip }}/{{ iface.prefix }}"
{% if iface.gateway | default('') | string | length %}
gateway4: "{{ iface.gateway }}"
{% endif %}
{% else %}
dhcp4: true
{% if dns_list | length or search_list | length %}
{% if loop.index0 == 0 and (dns_list | length or search_list | length) %}
dhcp4-overrides:
{% if dns_list | length %}
use-dns: false
@@ -25,7 +27,7 @@ network:
{% endif %}
{% endif %}
{% endif %}
{% if dns_list or search_list %}
{% if loop.index0 == 0 and (dns_list or search_list) %}
nameservers:
{% if dns_list %}
addresses:
@@ -40,3 +42,4 @@ network:
{% endfor %}
{% endif %}
{% endif %}
{% endfor %}

View File

@@ -46,11 +46,13 @@
<target dev="sdc" bus="sata"/>
</disk>
{% endif %}
{% for iface in system_cfg.network.interfaces %}
<interface type='network'>
<mac address="{{ virtualization_mac_address }}"/>
<source network='{{ system_cfg.network.bridge if (system_cfg.network.bridge | default('' ) | string | length) > 0 else "default" }}'/>
<mac address="{{ '52:54:00' | community.general.random_mac(seed=hostname if loop.index0 == 0 else hostname ~ '-nic' ~ loop.index0) }}"/>
<source network='{{ iface.bridge | default("default") }}'/>
<model type='virtio'/>
</interface>
{% endfor %}
{% if virtualization_tpm2_enabled %}
<tpm model='tpm-crb'>
<backend type='emulator' version='2.0'/>