--- - name: Write Alpine network interfaces ansible.builtin.copy: dest: /mnt/etc/network/interfaces mode: "0644" content: | auto lo iface lo inet loopback {% for iface in system_cfg.network.interfaces %} {% set inv_name = iface.name | default('') | string %} {% set det_name = configuration_detected_interfaces[loop.index0] | default('eth' ~ loop.index0) %} {% set iface_name = inv_name if inv_name | length > 0 else det_name %} {% set has_static = (iface.ip | default('') | string | length) > 0 %} auto {{ iface_name }} iface {{ iface_name }} inet {{ 'static' if has_static else 'dhcp' }} {% if has_static %} address {{ iface.ip }}/{{ iface.prefix }} {% if iface.gateway | default('') | string | length %} gateway {{ iface.gateway }} {% endif %} {% endif %} {% endfor %} - name: Set Alpine DNS resolvers when: configuration_dns_list | length > 0 or configuration_dns_search | length > 0 ansible.builtin.copy: dest: /mnt/etc/resolv.conf mode: "0644" content: | {% if configuration_dns_search | length > 0 %} search {{ configuration_dns_search | join(' ') }} {% endif %} {% for resolver in configuration_dns_list %} nameserver {{ resolver }} {% endfor %}