diff options
Diffstat (limited to 'roles/vm/host/network')
-rw-r--r-- | roles/vm/host/network/templates/bridge-interfaces.j2 | 30 | ||||
-rw-r--r-- | roles/vm/host/network/templates/interfaces.j2 | 44 |
2 files changed, 46 insertions, 28 deletions
diff --git a/roles/vm/host/network/templates/bridge-interfaces.j2 b/roles/vm/host/network/templates/bridge-interfaces.j2 index 4d80db4c..426f91f8 100644 --- a/roles/vm/host/network/templates/bridge-interfaces.j2 +++ b/roles/vm/host/network/templates/bridge-interfaces.j2 @@ -1,8 +1,8 @@ {% set bridge_name = 'br-'+item.key %} {% set bridge = item.value %} -{% set interface = (network.interfaces | selectattr('name', 'eq', bridge_name) | first | default({})) %} +{% set matched = (network.interfaces | selectattr('name', 'eq', bridge_name) | list) %} auto {{ bridge_name }} -iface {{ bridge_name }} inet {{ ('address' in interface) | ternary('static', 'manual') }} +iface {{ bridge_name }} inet {{ ((matched | length) == 0) | ternary('manual', 'static') }} up echo 0 > /proc/sys/net/ipv6/conf/$IFACE/accept_ra up echo 0 > /proc/sys/net/ipv6/conf/$IFACE/autoconf bridge_ports {{ bridge.interfaces | default(['none']) | join(' ') }} @@ -13,11 +13,12 @@ iface {{ bridge_name }} inet {{ ('address' in interface) | ternary('static', 'ma up /sbin/sysctl net.bridge.bridge-nf-call-iptables=0 up /sbin/sysctl net.bridge.bridge-nf-call-ip6tables=0 up /sbin/sysctl net.bridge.bridge-nf-call-arptables=0 -{% if 'address' in interface %} - address {{ interface.address | ipaddr('address') }} - netmask {{ interface.address | ipaddr('netmask') }} -{% if 'gateway' in interface %} - gateway {{ interface.gateway }} +{% if (matched | length) > 0 %} +{% set interface = matched | first %} +{% if 'content' in interface %} + {{ interface.content | indent(2) }} +{% else %} +{% include 'interfaces/' + (interface.template | default('simple')) + '.j2' %} {% endif %} {% if 'prefix' in bridge %} {% if 'nat' in bridge and bridge.nat %} @@ -26,7 +27,7 @@ iface {{ bridge_name }} inet {{ ('address' in interface) | ternary('static', 'ma up /sbin/iptables -t nat -A POSTROUTING -o {{ ansible_default_ipv4.interface }} -s {{ bridge.prefix }} -j SNAT --to {{ ansible_default_ipv4.address }} {% endif %} {% for overlay_name in (bridge.overlays | default({}) | list | sort) %} -{% set overlay = bridge.overlays[overlay_name] %} +{% set overlay = bridge.overlays[overlay_name] %} {% for dest, offset in (overlay.offsets | dictsort(by='value')) %} up /bin/ip route add {{ (overlay.prefix | ipaddr(offset)).split('/')[0] }}/32 via {{ (bridge.prefix | ipaddr(bridge.offsets[dest])).split('/')[0] }} # {{ dest }} {% endfor %} @@ -37,12 +38,13 @@ iface {{ bridge_name }} inet {{ ('address' in interface) | ternary('static', 'ma down /sbin/iptables -t nat -D POSTROUTING -o {{ ansible_default_ipv4.interface }} -s {{ bridge.prefix }} -j SNAT --to {{ ansible_default_ipv4.address }} {% endif %} {% endif %} -{% endif %} -{% if 'address6' in interface %} +{% if 'content6' in interface or 'address6' in interface %} -iface {{ bridge_name }} inet6 static - address {{ interface.address6 }} -{% if 'gateway6' in interface %} - gateway {{ interface.gateway6 }} +iface {{ interface.name }} inet6 static +{% if 'content6' in interface %} + {{ interface.content6 | indent(2) }} +{% else %} +{% include 'interfaces/' + (interface.template6 | default('simple6')) + '.j2' %} +{% endif %} {% endif %} {% endif %} diff --git a/roles/vm/host/network/templates/interfaces.j2 b/roles/vm/host/network/templates/interfaces.j2 index 6daa22bd..284c1cb6 100644 --- a/roles/vm/host/network/templates/interfaces.j2 +++ b/roles/vm/host/network/templates/interfaces.j2 @@ -19,9 +19,9 @@ iface {{ interface }} inet manual {% for bond in network.bonds | default([]) %} ## Bond: {{ bond.name }} -{% set tmp = network.interfaces | selectattr('name', 'eq', bond.name) | list %} +{% set matched = network.interfaces | selectattr('name', 'eq', bond.name) | list %} auto {{ bond.name }} -iface {{ bond.name }} inet {{ ((tmp | length) == 0) | ternary('manual', 'static') }} +iface {{ bond.name }} inet {{ ((matched | length) == 0) | ternary('manual', 'static') }} up echo 0 > /proc/sys/net/ipv6/conf/$IFACE/accept_ra up echo 0 > /proc/sys/net/ipv6/conf/$IFACE/autoconf bond-mode {{ bond.mode }} @@ -29,13 +29,21 @@ iface {{ bond.name }} inet {{ ((tmp | length) == 0) | ternary('manual', 'static' {% for option in (bond.options | default({}) | list | sort) %} bond-{{ option }} {{ bond.options[option] }} {% endfor %} -{% if (tmp | length) > 0 %} -{% set interface = tmp | first %} -{% include 'interfaces/' + (interface.config | default('simple')) + '.j2' %} -{% if 'address6' in interface %} +{% if (matched | length) > 0 %} +{% set interface = matched | first %} +{% if 'content' in interface %} + {{ interface.content | indent(2) }} +{% else %} +{% include 'interfaces/' + (interface.template | default('simple')) + '.j2' %} +{% endif %} +{% if 'content6' in interface or 'address6' in interface %} iface {{ interface.name }} inet6 static -{% include 'interfaces/' + (interface.config | default('simple6')) + '.j2' %} +{% if 'content6' in interface %} + {{ interface.content6 | indent(2) }} +{% else %} +{% include 'interfaces/' + (interface.template6 | default('simple6')) + '.j2' %} +{% endif %} {% endif %} {% endif %} @@ -46,18 +54,26 @@ iface {{ interface.name }} inet6 static {% for vlan in network.vlans[parent] %} {% set interface_name = parent+'.'+(vlan | string) %} -{% set tmp = network.interfaces | selectattr('name', 'eq', interface_name) | list %} +{% set matched = network.interfaces | selectattr('name', 'eq', interface_name) | list %} auto {{ interface_name }} -iface {{ interface_name }} inet {{ ((tmp | length) == 0) | ternary('manual', 'static') }} +iface {{ interface_name }} inet {{ ((matched | length) == 0) | ternary('manual', 'static') }} 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 %} -{% include 'interfaces/' + (interface.config | default('simple')) + '.j2' %} -{% if 'address6' in interface %} +{% if (matched | length) > 0 %} +{% set interface = matched | first %} +{% if 'content' in interface %} + {{ interface.content | indent(2) }} +{% else %} +{% include 'interfaces/' + (interface.template | default('simple')) + '.j2' %} +{% endif %} +{% if 'content6' in interface or 'address6' in interface %} iface {{ interface.name }} inet6 static -{% include 'interfaces/' + (interface.config | default('simple6')) + '.j2' %} +{% if 'content6' in interface %} + {{ interface.content6 | indent(2) }} +{% else %} +{% include 'interfaces/' + (interface.template6 | default('simple6')) + '.j2' %} +{% endif %} {% endif %} {% endif %} |