auto lo
iface lo inet loopback

{% for interface in network_interfaces %}
auto {{ interface.name }}

iface {{ interface.name }} inet {{ interface.ip4_type }}
{% if interface.ip4_type == 'dhcp' and interface.udhcpc_opts is string and dhcp_client == 'udhcpc' %}
    udhcpc_opts {{ interface.udhcpc_opts }}
{% endif %}
{% if interface.ip4_type == 'static' %}
    address {{ interface.ip4_addr | ansible.utils.ipv4('host/prefix') }}
    gateway {{ interface.ip4_gateway | ansible.utils.ipv4('address') }}
{% endif %}
    post-up /sbin/resolvconf -u

{#
Use SLAAC for udhcpc and dhclient, DHCPv6 for dhcpcd when ip6_type == 'auto'.
See https://wiki.alpinelinux.org/wiki/Configure_Networking#IPv6_DHCP_Configuration.
#}
{% if interface.ip6_type == 'static' or dhcp_client != 'dhcpcd' %}
iface {{ interface.name }} inet6 {{ interface.ip6_type }}
{% if interface.ip6_type == 'static' %}
    address {{ interface.ip6_addr | ansible.utils.ipv6('host/prefix') }}
    gateway {{ interface.ip6_gateway | ansible.utils.ipv6('address') }}
    pre-up echo 0 > /proc/sys/net/ipv6/conf/{{ interface.name }}/accept_ra
{% endif %}
    post-up /sbin/resolvconf -u
{% endif %}

{% endfor %}
