diff options
Diffstat (limited to 'roles/vm/host/network/templates/interfaces.j2')
-rw-r--r-- | roles/vm/host/network/templates/interfaces.j2 | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/roles/vm/host/network/templates/interfaces.j2 b/roles/vm/host/network/templates/interfaces.j2 new file mode 100644 index 00000000..fe57a024 --- /dev/null +++ b/roles/vm/host/network/templates/interfaces.j2 @@ -0,0 +1,79 @@ +# This file describes the network interfaces available on your system +# and how to activate them. For more information, see interfaces(5). + +# The loopback network interface +auto lo +iface lo inet loopback + + +## pyhiscal interfaces + +{% for interface in network.bonds | default([]) | map(attribute='slaves') | flatten | union(network.vlans | default({}) | list) | difference(network.bonds | default([]) | map(attribute='name') | list) | sort | unique %} +auto {{ interface }} +iface {{ interface }} inet manual + pre-up echo 0 > /proc/sys/net/ipv6/conf/$IFACE/accept_ra + pre-up echo 0 > /proc/sys/net/ipv6/conf/$IFACE/autoconf + +{% endfor %} + +{% for bond in network.bonds | default([]) %} +## Bond: {{ bond.name }} + +{% set tmp = network.interfaces | selectattr('name', 'eq', bond.name) | list %} +auto {{ bond.name }} +iface {{ bond.name }} inet {{ ((tmp | length) == 0) | ternary('manual', 'static') }} + bond-mode {{ bond.mode }} + bond-slaves {{ bond.slaves | sort | join(' ') }} +{% for option in (bond.options | default({}) | list | sort) %} + bond-{{ option }} {{ bond.options[option] }} +{% endfor %} + up echo 0 > /proc/sys/net/ipv6/conf/$IFACE/accept_ra + up echo 0 > /proc/sys/net/ipv6/conf/$IFACE/autoconf +{% if (tmp | length) > 0 %} +{% set interface = tmp | first %} + address {{ interface.address | ipaddr('address') }} + netmask {{ interface.address | ipaddr('netmask') }} +{% if 'gateway' in interface %} + gateway {{ interface.gateway }} +{% endif %} +{% for route in interface.static_routes | default([]) %} + up /bin/ip route add {{ route.destination }} via {{ route.gateway }} +{% endfor %} +{% for route in interface.static_routes | default([]) | reverse %} + down /bin/ip route del {{ route.destination }} via {{ route.gateway }} +{% endfor %} +{% if 'address6' in interface %} + +iface {{ interface.name }} inet6 static + address {{ interface.address6 }} +{% if 'gateway6' in interface %} + gateway {{ interface.gateway6 }} +{% endif %} +{% for route in interface.static_routes6 | default([]) %} + up /bin/ip -6 route add {{ route.destination }} via {{ route.gateway }} +{% endfor %} +{% for route in interface.static_routes6 | default([]) | reverse %} + down /bin/ip -6 route del {{ route.destination }} via {{ route.gateway }} +{% endfor %} +{% endif %} +{% endif %} + + +{% endfor %} +{% for parent in network.vlans | default({}) | list | sort %} +## vlan interfaces @ {{ parent }} + +{% for vlan in network.vlans[parent] %} +auto {{ parent }}.{{ vlan }} +iface {{ parent }}.{{ vlan }} inet manual + up echo 0 > /proc/sys/net/ipv6/conf/$IFACE/accept_ra + up echo 0 > /proc/sys/net/ipv6/conf/$IFACE/autoconf +{# TODO: add interface config like above if (network.interfaces | selectattr('name', 'eq', 'parent+'.'+vlan') | list) > 0 ... #} + +{% endfor %} + +{% endfor %} + +## source bridge configs + +source /etc/network/interfaces.d/* |