summaryrefslogtreecommitdiff
path: root/roles/vm/host/network/templates
diff options
context:
space:
mode:
Diffstat (limited to 'roles/vm/host/network/templates')
-rw-r--r--roles/vm/host/network/templates/bridge-interfaces.j249
-rw-r--r--roles/vm/host/network/templates/interfaces.j245
-rw-r--r--roles/vm/host/network/templates/interfaces/simple.j211
-rw-r--r--roles/vm/host/network/templates/interfaces/simple6.j210
4 files changed, 61 insertions, 54 deletions
diff --git a/roles/vm/host/network/templates/bridge-interfaces.j2 b/roles/vm/host/network/templates/bridge-interfaces.j2
index 05144430..4d80db4c 100644
--- a/roles/vm/host/network/templates/bridge-interfaces.j2
+++ b/roles/vm/host/network/templates/bridge-interfaces.j2
@@ -2,45 +2,40 @@
{% set bridge = item.value %}
{% set interface = (network.interfaces | selectattr('name', 'eq', bridge_name) | first | default({})) %}
auto {{ bridge_name }}
-{% if 'address' in interface %}
-iface {{ bridge_name }} inet static
- address {{ interface.address | ipaddr('address') }}
- netmask {{ interface.address | ipaddr('netmask') }}
-{% if 'gateway' in interface %}
- gateway {{ interface.gateway }}
-{% endif %}
-{% else %}
-iface {{ bridge_name }} inet manual
-{% endif %}
-{% if 'interfaces' in bridge and (bridge.interfaces | length) > 0 %}
- bridge_ports {{ bridge.interfaces | join(' ') }}
-{% else %}
- bridge_ports none
-{% endif %}
+iface {{ bridge_name }} inet {{ ('address' in interface) | ternary('static', 'manual') }}
+ 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(' ') }}
bridge_stp off
bridge_waitport 0
bridge_fd 0
- up echo 0 > /proc/sys/net/ipv6/conf/$IFACE/accept_ra
- up echo 0 > /proc/sys/net/ipv6/conf/$IFACE/autoconf
up modprobe br_netfilter
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 and 'prefix' in bridge %}
-{% if 'nat' in bridge and bridge.nat %}
+{% if 'address' in interface %}
+ address {{ interface.address | ipaddr('address') }}
+ netmask {{ interface.address | ipaddr('netmask') }}
+{% if 'gateway' in interface %}
+ gateway {{ interface.gateway }}
+{% endif %}
+{% if 'prefix' in bridge %}
+{% if 'nat' in bridge and bridge.nat %}
up echo 1 > /proc/sys/net/ipv4/conf/$IFACE/forwarding
up echo 1 > /proc/sys/net/ipv4/conf/{{ ansible_default_ipv4.interface }}/forwarding
up /sbin/iptables -t nat -A POSTROUTING -o {{ ansible_default_ipv4.interface }} -s {{ bridge.prefix }} -j SNAT --to {{ ansible_default_ipv4.address }}
-{% endif %}
-{% if 'overlay' in bridge %}
-{% for dest, offset in (bridge.overlay.offsets | dictsort(by='value')) %}
- up /bin/ip route add {{ (bridge.overlay.prefix | ipaddr(offset)).split('/')[0] }}/32 via {{ (bridge.prefix | ipaddr(bridge.offsets[dest])).split('/')[0] }} # {{ dest }}
+{% endif %}
+{% for overlay_name in (bridge.overlays | default({}) | list | sort) %}
+{% 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 %}
+ up /bin/ip route add unreachable {{ overlay.prefix }}
+ down /sbin/ip route del {{ overlay.prefix }}
{% endfor %}
- up /bin/ip route add unreachable {{ bridge.overlay.prefix }}
- down /sbin/ip route del {{ bridge.overlay.prefix }}
-{% endif %}
-{% if 'nat' in bridge and bridge.nat %}
+{% if 'nat' in bridge and bridge.nat %}
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 %}
diff --git a/roles/vm/host/network/templates/interfaces.j2 b/roles/vm/host/network/templates/interfaces.j2
index fe57a024..6daa22bd 100644
--- a/roles/vm/host/network/templates/interfaces.j2
+++ b/roles/vm/host/network/templates/interfaces.j2
@@ -22,53 +22,44 @@ iface {{ interface }} inet manual
{% set tmp = network.interfaces | selectattr('name', 'eq', bond.name) | list %}
auto {{ bond.name }}
iface {{ bond.name }} inet {{ ((tmp | 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 }}
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 %}
+{% include 'interfaces/' + (interface.config | default('simple')) + '.j2' %}
{% 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 %}
+{% include 'interfaces/' + (interface.config | default('simple6')) + '.j2' %}
{% endif %}
{% endif %}
{% endfor %}
-{% for parent in network.vlans | default({}) | list | sort %}
+{% 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
+{% set interface_name = parent+'.'+(vlan | string) %}
+{% set tmp = network.interfaces | selectattr('name', 'eq', interface_name) | list %}
+auto {{ interface_name }}
+iface {{ interface_name }} inet {{ ((tmp | 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
-{# TODO: add interface config like above if (network.interfaces | selectattr('name', 'eq', 'parent+'.'+vlan') | list) > 0 ... #}
+{% if (tmp | length) > 0 %}
+{% set interface = tmp | first %}
+{% include 'interfaces/' + (interface.config | default('simple')) + '.j2' %}
+{% if 'address6' in interface %}
+
+iface {{ interface.name }} inet6 static
+{% include 'interfaces/' + (interface.config | default('simple6')) + '.j2' %}
+{% endif %}
+{% endif %}
{% endfor %}
diff --git a/roles/vm/host/network/templates/interfaces/simple.j2 b/roles/vm/host/network/templates/interfaces/simple.j2
new file mode 100644
index 00000000..c5b7dadc
--- /dev/null
+++ b/roles/vm/host/network/templates/interfaces/simple.j2
@@ -0,0 +1,11 @@
+ 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 }}{% if 'source' in route %} src {{ route.source }}{% endif %}
+{% endfor %}
+{% for route in interface.static_routes | default([]) | reverse %}
+ down /bin/ip route del {{ route.destination }} via {{ route.gateway }}{% if 'source' in route %} src {{ route.source }}{% endif %}
+{% endfor %}
diff --git a/roles/vm/host/network/templates/interfaces/simple6.j2 b/roles/vm/host/network/templates/interfaces/simple6.j2
new file mode 100644
index 00000000..37fda07a
--- /dev/null
+++ b/roles/vm/host/network/templates/interfaces/simple6.j2
@@ -0,0 +1,10 @@
+ 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 }}{% if 'source' in route %} src {{ route.source }}{% endif %}
+{% endfor %}
+{% for route in interface.static_routes6 | default([]) | reverse %}
+ down /bin/ip -6 route del {{ route.destination }} via {{ route.gateway }}{% if 'source' in route %} src {{ route.source }}{% endif %}
+{% endfor %}