From c93f3ec6ef4bd6c735bda70ecc20790ec6e8b28f Mon Sep 17 00:00:00 2001 From: melissaml Date: Wed, 23 May 2018 21:12:51 +0800 Subject: [PATCH] Add a single variable for combined networks The combined networks variable will allow deployers to set basic container networks, default nspawn networks, and any "extra" networks a deployer may need outside of a standard build. Change-Id: I0cfed0ad6cce99c420c31920446e0a69a82fa602 Signed-off-by: Kevin Carter --- tasks/main.yml | 2 +- templates/container_config.nspawn.j2 | 3 +-- templates/container_config_old.nspawn.j2 | 3 +-- vars/main.yml | 17 +++++++++++++++++ 4 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 vars/main.yml diff --git a/tasks/main.yml b/tasks/main.yml index cb71c08..6e86784 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -336,7 +336,7 @@ Domains: "{{ container_domain }}" systemd_networks: |- {% set _networks = [] %} - {% for _, value in (container_networks | combine(nspawn_networks)).items() %} + {% for _, value in nspawn_combined_networks.items() %} {% if value.bridge is defined %} {% set _network = {'interface': 'mv-mv-' + value.bridge.split('br-')[-1]} %} {% else %} diff --git a/templates/container_config.nspawn.j2 b/templates/container_config.nspawn.j2 index c118b19..180db65 100644 --- a/templates/container_config.nspawn.j2 +++ b/templates/container_config.nspawn.j2 @@ -24,8 +24,7 @@ Bind={{ bind }}:{{ bind }} [Network] {% set macvlans = [] %} -{% set _ = container_networks.update(nspawn_networks) %} -{% for key, value in container_networks.items() %} +{% for key, value in nspawn_combined_networks.items() %} {% if value.bridge is defined %} {% set _ = macvlans.append('mv-' + value.bridge.split('br-')[-1]) %} {% endif %} diff --git a/templates/container_config_old.nspawn.j2 b/templates/container_config_old.nspawn.j2 index 4b87edb..0e8f4ee 100644 --- a/templates/container_config_old.nspawn.j2 +++ b/templates/container_config_old.nspawn.j2 @@ -18,8 +18,7 @@ {% endfor %} {% endif %} {% set macvlans = [] %} -{% set _ = container_networks.update(nspawn_networks) %} -{% for key, value in container_networks.items() %} +{% for key, value in nspawn_combined_networks.items() %} {% if value.bridge is defined %} {% set macvlan = 'mv-' + value.bridge.split('br-')[-1] %} {% endif %} diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..ed14564 --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,17 @@ +--- +# Copyright 2018, Rackspace US, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A combined hash of all networks to be used within a deployment. +nspawn_combined_networks: "{{ container_networks | combine(container_extra_networks | default({})) | combine(nspawn_networks) }}"