--- - name: Set DNS configuration facts ansible.builtin.set_fact: configuration_dns_list: "{{ system_cfg.network.dns.servers }}" configuration_dns_search: "{{ system_cfg.network.dns.search }}" # 2+ unnamed interfaces would all match the first-ethernet glob, leaving the rest unconfigured. - name: Require an explicit name on every interface for multi-NIC vars: _unnamed: "{{ system_cfg.network.interfaces | map(attribute='name', default='') | map('string') | select('equalto', '') | list | length }}" ansible.builtin.assert: that: - system_cfg.network.interfaces | length <= 1 or _unnamed == 0 fail_msg: >- Multi-NIC (system.network.interfaces with 2+ entries) requires a name on every interface; the first-adapter glob only binds a single NIC. # Probe /mnt to detect the stack the installed rootfs will run (nothing runs in # the chroot). NM is checked first and wins, since bootstrap installs it on every # family; the rest are the fallback for a non-NM base image. - name: Probe the installed network stack on the target rootfs ansible.builtin.stat: path: "{{ item }}" register: configuration_net_probe loop: - /mnt/usr/bin/nmcli - /mnt/usr/lib/systemd/system/NetworkManager.service - /mnt/usr/sbin/netplan - /mnt/etc/netplan - /mnt/sbin/ifup - /mnt/usr/sbin/ifup - /mnt/etc/systemd/system/multi-user.target.wants/systemd-networkd.service - /mnt/etc/systemd/system/dbus-org.freedesktop.network1.service loop_control: label: "{{ item }}" - name: Resolve the network backend from the probe vars: _found: "{{ configuration_net_probe.results | selectattr('stat.exists') | map(attribute='item') | list }}" ansible.builtin.set_fact: configuration_network_backend: >- {{ 'nm' if (['/mnt/usr/bin/nmcli', '/mnt/usr/lib/systemd/system/NetworkManager.service'] | intersect(_found)) else 'netplan' if (['/mnt/usr/sbin/netplan', '/mnt/etc/netplan'] | intersect(_found)) else 'eni' if (['/mnt/sbin/ifup', '/mnt/usr/sbin/ifup'] | intersect(_found)) else 'networkd' if (['/mnt/etc/systemd/system/multi-user.target.wants/systemd-networkd.service', '/mnt/etc/systemd/system/dbus-org.freedesktop.network1.service'] | intersect(_found)) else 'nm' }} - name: Configure networking for the detected backend {{ configuration_network_backend }} ansible.builtin.include_tasks: "network_{{ configuration_network_backend }}.yml"