diff options
21 files changed, 148 insertions, 112 deletions
diff --git a/chaos-at-home/generic.yml b/chaos-at-home/generic.yml index bc8866c5..9a495ffb 100644 --- a/chaos-at-home/generic.yml +++ b/chaos-at-home/generic.yml @@ -1,5 +1,11 @@ --- - name: "Apply role {{ myrole }} to hosts: {{ myhosts }}" hosts: "{{ myhosts }}" + pre_tasks: + - name: cook some variables for roles that expect them to be cooked + set_fact: + install_cooked: "{{ install | default({}) }}" + network_cooked: "{{ network | default({}) }}" + vm_host_cooked: "{{ vm_host | default({}) }}" roles: - role: "{{ myrole }}" diff --git a/dan/generic.yml b/dan/generic.yml index bc8866c5..9a495ffb 100644 --- a/dan/generic.yml +++ b/dan/generic.yml @@ -1,5 +1,11 @@ --- - name: "Apply role {{ myrole }} to hosts: {{ myhosts }}" hosts: "{{ myhosts }}" + pre_tasks: + - name: cook some variables for roles that expect them to be cooked + set_fact: + install_cooked: "{{ install | default({}) }}" + network_cooked: "{{ network | default({}) }}" + vm_host_cooked: "{{ vm_host | default({}) }}" roles: - role: "{{ myrole }}" diff --git a/inventory/group_vars/vmhost-sk-2019vm/main.yml b/inventory/group_vars/vmhost-sk-2019vm/main.yml index 254d6d8b..4786040b 100644 --- a/inventory/group_vars/vmhost-sk-2019vm/main.yml +++ b/inventory/group_vars/vmhost-sk-2019vm/main.yml @@ -18,15 +18,16 @@ vm_host: sk-testvm: 253 sk-2019vm: 254 nat: yes - overlay: - prefix: 178.63.180.136/29 - offsets: - sk-torrent: 0 -# emc-master: 1 - lw-master: 1 - ele-gwhetzner: 2 - ch-mimas: 6 - sk-testvm: 7 + overlays: + default: + prefix: 178.63.180.136/29 + offsets: + sk-torrent: 0 +# emc-master: 1 + lw-master: 1 + ele-gwhetzner: 2 + ch-mimas: 6 + sk-testvm: 7 zfs: default: pool: storage diff --git a/inventory/group_vars/vmhost-sk-tomnext/main.yml b/inventory/group_vars/vmhost-sk-tomnext/main.yml index eacc58a2..a3706dcd 100644 --- a/inventory/group_vars/vmhost-sk-tomnext/main.yml +++ b/inventory/group_vars/vmhost-sk-tomnext/main.yml @@ -14,11 +14,12 @@ vm_host: sk-tomnext-hp: 104 sk-tomnext: 254 nat: yes - overlay: - prefix: 94.130.206.64/26 - offsets: - sk-tomnext-nc: 39 - sk-tomnext-hp: 40 + overlays: + default: + prefix: 94.130.206.64/26 + offsets: + sk-tomnext-nc: 39 + sk-tomnext-hp: 40 zfs: default: pool: storage diff --git a/inventory/host_vars/ch-mimas.yml b/inventory/host_vars/ch-mimas.yml index 38422a30..b8f49a4a 100644 --- a/inventory/host_vars/ch-mimas.yml +++ b/inventory/host_vars/ch-mimas.yml @@ -24,7 +24,8 @@ network: name: eth0 address: "{{ vm_host.network.bridges.public.prefix | ipaddr(vm_host.network.bridges.public.offsets[inventory_hostname]) | ipaddr('address/prefix') }}" gateway: "{{ vm_host.network.bridges.public.prefix | ipaddr(vm_host.network.bridges.public.offsets[vm_host.name]) | ipaddr('address') }}" - overlay: "{{ (vm_host.network.bridges.public.overlay.prefix | ipaddr(vm_host.network.bridges.public.overlay.offsets[inventory_hostname])).split('/')[0] }}" + config: overlay + overlay: "{{ (vm_host.network.bridges.public.overlays.default.prefix | ipaddr(vm_host.network.bridges.public.overlays.default.offsets[inventory_hostname])).split('/')[0] }}" interfaces: - *_network_primary_ diff --git a/inventory/host_vars/ele-gwhetzner.yml b/inventory/host_vars/ele-gwhetzner.yml index 3be84fd7..fe0dc028 100644 --- a/inventory/host_vars/ele-gwhetzner.yml +++ b/inventory/host_vars/ele-gwhetzner.yml @@ -24,7 +24,8 @@ network: name: primary0 address: "{{ vm_host.network.bridges.public.prefix | ipaddr(vm_host.network.bridges.public.offsets[inventory_hostname]) | ipaddr('address/prefix') }}" gateway: "{{ vm_host.network.bridges.public.prefix | ipaddr(vm_host.network.bridges.public.offsets[vm_host.name]) | ipaddr('address') }}" - overlay: "{{ (vm_host.network.bridges.public.overlay.prefix | ipaddr(vm_host.network.bridges.public.overlay.offsets[inventory_hostname])).split('/')[0] }}" + config: overlay + overlay: "{{ (vm_host.network.bridges.public.overlays.default.prefix | ipaddr(vm_host.network.bridges.public.overlays.default.offsets[inventory_hostname])).split('/')[0] }}" interfaces: - *_network_primary_ diff --git a/inventory/host_vars/emc-master.yml b/inventory/host_vars/emc-master.yml index dcf51a45..f7d3e5c9 100644 --- a/inventory/host_vars/emc-master.yml +++ b/inventory/host_vars/emc-master.yml @@ -27,7 +27,8 @@ network: name: primary0 address: "{{ vm_host.network.bridges.public.prefix | ipaddr(vm_host.network.bridges.public.offsets[inventory_hostname]) | ipaddr('address/prefix') }}" gateway: "{{ vm_host.network.bridges.public.prefix | ipaddr(vm_host.network.bridges.public.offsets[vm_host.name]) | ipaddr('address') }}" - overlay: "{{ (vm_host.network.bridges.public.overlay.prefix | ipaddr(vm_host.network.bridges.public.overlay.offsets[inventory_hostname])).split('/')[0] }}" + config: overlay + overlay: "{{ (vm_host.network.bridges.public.overlays.default.prefix | ipaddr(vm_host.network.bridges.public.overlays.default.offsets[inventory_hostname])).split('/')[0] }}" interfaces: - *_network_primary_ diff --git a/inventory/host_vars/lw-master.yml b/inventory/host_vars/lw-master.yml index dcf51a45..f7d3e5c9 100644 --- a/inventory/host_vars/lw-master.yml +++ b/inventory/host_vars/lw-master.yml @@ -27,7 +27,8 @@ network: name: primary0 address: "{{ vm_host.network.bridges.public.prefix | ipaddr(vm_host.network.bridges.public.offsets[inventory_hostname]) | ipaddr('address/prefix') }}" gateway: "{{ vm_host.network.bridges.public.prefix | ipaddr(vm_host.network.bridges.public.offsets[vm_host.name]) | ipaddr('address') }}" - overlay: "{{ (vm_host.network.bridges.public.overlay.prefix | ipaddr(vm_host.network.bridges.public.overlay.offsets[inventory_hostname])).split('/')[0] }}" + config: overlay + overlay: "{{ (vm_host.network.bridges.public.overlays.default.prefix | ipaddr(vm_host.network.bridges.public.overlays.default.offsets[inventory_hostname])).split('/')[0] }}" interfaces: - *_network_primary_ diff --git a/inventory/host_vars/sk-testvm.yml b/inventory/host_vars/sk-testvm.yml index 86c00c1f..e0e86352 100644 --- a/inventory/host_vars/sk-testvm.yml +++ b/inventory/host_vars/sk-testvm.yml @@ -24,7 +24,8 @@ network: name: primary0 address: "{{ vm_host.network.bridges.public.prefix | ipaddr(vm_host.network.bridges.public.offsets[inventory_hostname]) | ipaddr('address/prefix') }}" gateway: "{{ vm_host.network.bridges.public.prefix | ipaddr(vm_host.network.bridges.public.offsets[vm_host.name]) | ipaddr('address') }}" - overlay: "{{ (vm_host.network.bridges.public.overlay.prefix | ipaddr(vm_host.network.bridges.public.overlay.offsets[inventory_hostname])).split('/')[0] }}" + config: overlay + overlay: "{{ (vm_host.network.bridges.public.overlays.default.prefix | ipaddr(vm_host.network.bridges.public.overlays.default.offsets[inventory_hostname])).split('/')[0] }}" interfaces: - *_network_primary_ diff --git a/inventory/host_vars/sk-tomnext-hp.yml b/inventory/host_vars/sk-tomnext-hp.yml index 8975e5a3..5bf39fd8 100644 --- a/inventory/host_vars/sk-tomnext-hp.yml +++ b/inventory/host_vars/sk-tomnext-hp.yml @@ -31,7 +31,8 @@ network: name: primary0 address: "{{ vm_host.network.bridges.public.prefix | ipaddr(vm_host.network.bridges.public.offsets[inventory_hostname]) | ipaddr('address/prefix') }}" gateway: "{{ vm_host.network.bridges.public.prefix | ipaddr(vm_host.network.bridges.public.offsets[vm_host.name]) | ipaddr('address') }}" - overlay: "{{ (vm_host.network.bridges.public.overlay.prefix | ipaddr(vm_host.network.bridges.public.overlay.offsets[inventory_hostname])).split('/')[0] }}" + config: overlay + overlay: "{{ (vm_host.network.bridges.public.overlays.default.prefix | ipaddr(vm_host.network.bridges.public.overlays.default.offsets[inventory_hostname])).split('/')[0] }}" interfaces: - *_network_primary_ diff --git a/inventory/host_vars/sk-tomnext-nc.yml b/inventory/host_vars/sk-tomnext-nc.yml index 340795eb..652770d4 100644 --- a/inventory/host_vars/sk-tomnext-nc.yml +++ b/inventory/host_vars/sk-tomnext-nc.yml @@ -30,7 +30,8 @@ network: name: primary0 address: "{{ vm_host.network.bridges.public.prefix | ipaddr(vm_host.network.bridges.public.offsets[inventory_hostname]) | ipaddr('address/prefix') }}" gateway: "{{ vm_host.network.bridges.public.prefix | ipaddr(vm_host.network.bridges.public.offsets[vm_host.name]) | ipaddr('address') }}" - overlay: "{{ (vm_host.network.bridges.public.overlay.prefix | ipaddr(vm_host.network.bridges.public.overlay.offsets[inventory_hostname])).split('/')[0] }}" + config: overlay + overlay: "{{ (vm_host.network.bridges.public.overlays.default.prefix | ipaddr(vm_host.network.bridges.public.overlays.default.offsets[inventory_hostname])).split('/')[0] }}" interfaces: - *_network_primary_ diff --git a/inventory/host_vars/sk-torrent.yml b/inventory/host_vars/sk-torrent.yml index c8967dab..a164b7b0 100644 --- a/inventory/host_vars/sk-torrent.yml +++ b/inventory/host_vars/sk-torrent.yml @@ -28,7 +28,8 @@ network: name: primary0 address: "{{ vm_host.network.bridges.public.prefix | ipaddr(vm_host.network.bridges.public.offsets[inventory_hostname]) | ipaddr('address/prefix') }}" gateway: "{{ vm_host.network.bridges.public.prefix | ipaddr(vm_host.network.bridges.public.offsets[vm_host.name]) | ipaddr('address') }}" - overlay: "{{ (vm_host.network.bridges.public.overlay.prefix | ipaddr(vm_host.network.bridges.public.overlay.offsets[inventory_hostname])).split('/')[0] }}" + config: overlay + overlay: "{{ (vm_host.network.bridges.public.overlays.default.prefix | ipaddr(vm_host.network.bridges.public.overlays.default.offsets[inventory_hostname])).split('/')[0] }}" interfaces: - *_network_primary_ diff --git a/roles/vm/guest/network/templates/interfaces.j2 b/roles/vm/guest/network/templates/interfaces.j2 index 8c288669..8e2f324c 100644 --- a/roles/vm/guest/network/templates/interfaces.j2 +++ b/roles/vm/guest/network/templates/interfaces.j2 @@ -13,44 +13,10 @@ auto {{ interface.name }} iface {{ interface.name }} inet static pre-up echo 0 > /proc/sys/net/ipv6/conf/$IFACE/accept_ra pre-up echo 0 > /proc/sys/net/ipv6/conf/$IFACE/autoconf - address {{ interface.address | ipaddr('address') }} - netmask {{ interface.address | ipaddr('netmask') }} -{% if 'overlay' in interface %} - up /bin/ip addr add dev $IFACE {{ interface.overlay }}/32 -{% for route in interface.static_routes | default([]) %} - up /bin/ip route add {{ route.destination }} via {{ route.gateway }} src {{ interface.overlay }} -{% endfor %} -{% if 'gateway' in interface %} - up /bin/ip route add default via {{ interface.gateway }} src {{ interface.overlay }} - down /bin/ip route del default via {{ interface.gateway }} src {{ interface.overlay }} -{% for route in interface.static_routes | default([]) | reverse %} - down /bin/ip route del {{ route.destination }} via {{ route.gateway }} src {{ interface.overlay }} -{% endfor %} -{% endif %} - down /bin/ip addr del dev $IFACE {{ interface.overlay }}/32 -{% else %} -{% 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 %} -{% endif %} +{% 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 %} {% endfor %} diff --git a/roles/vm/guest/network/templates/interfaces/overlay.j2 b/roles/vm/guest/network/templates/interfaces/overlay.j2 new file mode 100644 index 00000000..a3262f9c --- /dev/null +++ b/roles/vm/guest/network/templates/interfaces/overlay.j2 @@ -0,0 +1,14 @@ + address {{ interface.address | ipaddr('address') }} + netmask {{ interface.address | ipaddr('netmask') }} + up /bin/ip addr add dev $IFACE {{ interface.overlay }}/32 +{% 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 %} +{% if 'gateway' in interface %} + up /bin/ip route add default via {{ interface.gateway }} src {{ interface.overlay }} + down /bin/ip route del default via {{ interface.gateway }} src {{ interface.overlay }} +{% 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 %} +{% endif %} + down /bin/ip addr del dev $IFACE {{ interface.overlay }}/32 diff --git a/roles/vm/guest/network/templates/interfaces/simple.j2 b/roles/vm/guest/network/templates/interfaces/simple.j2 new file mode 100644 index 00000000..c5b7dadc --- /dev/null +++ b/roles/vm/guest/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/guest/network/templates/interfaces/simple6.j2 b/roles/vm/guest/network/templates/interfaces/simple6.j2 new file mode 100644 index 00000000..37fda07a --- /dev/null +++ b/roles/vm/guest/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 %} 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 %} diff --git a/spreadspace/generic.yml b/spreadspace/generic.yml index bc8866c5..9a495ffb 100644 --- a/spreadspace/generic.yml +++ b/spreadspace/generic.yml @@ -1,5 +1,11 @@ --- - name: "Apply role {{ myrole }} to hosts: {{ myhosts }}" hosts: "{{ myhosts }}" + pre_tasks: + - name: cook some variables for roles that expect them to be cooked + set_fact: + install_cooked: "{{ install | default({}) }}" + network_cooked: "{{ network | default({}) }}" + vm_host_cooked: "{{ vm_host | default({}) }}" roles: - role: "{{ myrole }}" |