Ignore OOB management interface, allow configuring loopback interface with NetBox data, and setting MTU.
38 lines
1.3 KiB
Django/Jinja
38 lines
1.3 KiB
Django/Jinja
{# Loopback interface must be present so define it here if none exists. #}
|
|
{% if interfaces | rejectattr("name", "==", "lo") %}
|
|
auto lo
|
|
iface lo inet loopback
|
|
|
|
{% 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 {% 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 %}
|
|
{% 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
|