alpine: support non-VM hosts in interfaces template

Ignore OOB management interface, allow configuring loopback interface
with NetBox data, and setting MTU.
This commit is contained in:
Timotej Lazar 2025-05-15 14:55:43 +02:00
parent cbd3f1a7ea
commit bf4fd2c82d
2 changed files with 38 additions and 3 deletions

View file

@ -1,9 +1,21 @@
{# Loopback interface must be present so define it here if none exists. #}
{% if interfaces | rejectattr("name", "==", "lo") %}
auto lo
iface lo inet loopback
{% for iface in interfaces | selectattr('enabled') %}
{% 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 }} inet static
iface {{ iface.name }} inet {% if iface.name == "lo" %}loopback{% else %}static{% endif +%}
{% if iface.mtu %}
mtu {{ iface.mtu }}
{% endif %}
{% for address in iface.ip_addresses %}
address {{ address.address }}
{% if address.family.value == 4 %}
@ -21,4 +33,6 @@ iface {{ iface.name }} inet static
pre-up echo 0 > /proc/sys/net/ipv6/conf/$IFACE/autoconf
{% endif %}
{% endfor %}
{% endfor -%}
source-directory /etc/network/interfaces.d