44 lines
1.5 KiB
Django/Jinja
44 lines
1.5 KiB
Django/Jinja
# {{ ansible_managed }}
|
|
|
|
{% macro iface_config(iface, type, inet) %}
|
|
iface {{ iface.name }} {{ type }} {{ inet.conf | default('manual') }}
|
|
{% if iface.vlan_raw_device is defined %}
|
|
vlan-raw-device {{ iface.vlan_raw_device }}
|
|
{% endif %}
|
|
{% if iface.dummy | default(false) %}
|
|
pre-up ip link show $IFACE > /dev/null || sudo ip link add $IFACE type dummy
|
|
post-down ip link show $IFACE > /dev/null && sudo ip link del $IFACE
|
|
{% endif %}
|
|
{% for addr in inet.addr %}
|
|
up ip addr add {{ addr }} dev $IFACE
|
|
pre-down ip addr del {{ addr }} dev $IFACE
|
|
{% endfor %}
|
|
{% if inet.gateway is defined and inet.gateway %}
|
|
up ip r add default via {{ inet.gateway }} dev $IFACE
|
|
pre-down ip r del default via {{ inet.gateway }} dev $IFACE
|
|
{% endif %}
|
|
{% if inet.routes is defined and inet.routes %}
|
|
{% for route in inet.routes %}
|
|
post-up ip r add {{ route.dst }} via {{ route.via }} dev $IFACE
|
|
pre-down ip r del {{ route.dst }} via {{ route.via }} dev $IFACE
|
|
{% endfor %}
|
|
{% endif %}
|
|
{% if inet.custom is defined and inet.custom %}
|
|
{{ inet.custom | default('') | indent(4) }}
|
|
{% endif %}
|
|
{% endmacro %}
|
|
|
|
{% for iface in net_interfaces %}
|
|
{% if interfaces_manage_ifupdown or (iface.ifupdown | default(false)) %}
|
|
# {{ iface.name }}
|
|
allow-hotplug {{ iface.name }}
|
|
{% if iface.inet is defined and iface.inet %}
|
|
{{ iface_config(iface, 'inet', iface.inet) }}
|
|
{% endif %}
|
|
{% if iface.inet6 is defined and iface.inet6 %}
|
|
{{ iface_config(iface, 'inet6', iface.inet6) }}
|
|
{% endif %}
|
|
|
|
{% endif %}
|
|
{% endfor %}
|