servers/roles/alpine/templates/interfaces.j2
Timotej Lazar d1cf462f64 alpine: drop hints from interface configuration
Turns out ifupdown-ng ignores "inet static" and "inet loopback" hints
on iface lines. The interface named "lo" is always used as loopback.
2025-07-16 13:07:15 +02:00

38 lines
1.2 KiB
Django/Jinja

{# Loopback interface must be present so define it here if none exists. #}
{% if interfaces | rejectattr("name", "==", "lo") %}
auto lo
iface lo
{% endif -%}
{# Skip disabled and OOB management interfaces. #}
{# For VMs we have to set the attribute manually (to false) so rejectattr works. #}
{% for iface in interfaces
| defaultattr('mgmt_only')
| rejectattr('mgmt_only')
| selectattr('enabled') %}
auto {{ iface.name }}
iface {{ iface.name }}
{% if iface.mtu %}
mtu {{ iface.mtu }}
{% endif %}
{% for address in iface.ip_addresses %}
address {{ address.address }}
{% if address.family.value == 4 %}
{% set subnet = address.address | ipaddr('subnet') %}
{% set prefix = prefixes | selectattr('prefix', '==', subnet) | first %}
{% set gateway = prefix.custom_fields.gateway.address %}
{% if gateway is defined and gateway != address.address %}
gateway {{ gateway | ipaddr('address') }}
{% endif %}
{% endif %}
{% endfor -%}
{# disable SLAAC if we have a manually set IPv6 address #}
{% if iface.ip_addresses | selectattr("family.value", "==", 6) %}
pre-up echo 0 > /proc/sys/net/ipv6/conf/$IFACE/autoconf
{% endif %}
{% endfor -%}
source-directory /etc/network/interfaces.d