diff --git a/defaults/main.yml b/defaults/main.yml index a4526e7..bc8a80b 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -33,6 +33,8 @@ nspawn_networks: netmask: 255.255.255.0 # Optional | Set the macvlan mode macvlan_mode: bridge + # Optional | set the routed interface + routed_interface: mv-nspawn0 # Primary interface used for host to container communications. In the event that # the underlying system is running a condensed network stack a route will be @@ -57,6 +59,7 @@ nspawn_networks: # + simple example: # management_cidr: "172.29.236.0/24" # storage_cidr: "10.0.0.0/24" +# flat_cidr: "172.29.239.0/24" # container_networks: # management_address: # bridge: eth0 @@ -66,6 +69,10 @@ nspawn_networks: # netmask: 255.255.255.0 # tunnel_address: # bridge: eth0.10 +# flat_address: +# bridge: eth0 +# interface: mv-flat +# routed_interface: mv-flat # # Extra interfaces that are wholly configured by the user can be set using the # container extra networks option. This option follows all of the parameters of @@ -80,6 +87,8 @@ container_extra_networks: {} # assigned to the underlying interface, "eth0". # + The tunnel network will be attached to the container and isolated from the # host with no access to without first attaching to the container. +# + The flat network will be created and attached to the container with a host +# route on the defined `routed_interface`. # nspawn_primary_interface: "{{ nspawn_networks['nspawn_address']['bridge'] }}" diff --git a/tasks/nspawn_networking.yml b/tasks/nspawn_networking.yml index c5fde41..e322172 100644 --- a/tasks/nspawn_networking.yml +++ b/tasks/nspawn_networking.yml @@ -101,7 +101,7 @@ {%- set _ = start_commands.append('-/sbin/ip link set dev ' + mv_interface + ' up') %} {% if hostvars[inventory_hostname][key.split('_')[0] + '_cidr'] is defined and (value.address is undefined) %} {% set net_cidr = hostvars[inventory_hostname][key.split('_')[0] + '_cidr'] %} - {% set _ = start_commands.append('-/sbin/ip route add ' + net_cidr + ' dev ' + nspawn_primary_interface + ' metric 100 proto kernel scope link table local') %} + {% set _ = start_commands.append('-/sbin/ip route add ' + net_cidr + ' dev ' + (value.routed_interface | default(nspawn_primary_interface)) + ' metric 100 proto kernel scope link table local') %} {% elif (value.address is defined) and ((interface_data['ipv4'] | default({'address': none}))['address'] != value.address) %} {% set _ = start_commands.append('-/sbin/ip address add ' + value.address + '/' + (value.netmask | default('32')) + ' dev ' + mv_interface + ' scope host') %} {%- endif %}