From 789aaa4e738ae7027d57fde30992d8dde05fcb48 Mon Sep 17 00:00:00 2001 From: Logan V Date: Sun, 23 Apr 2017 20:48:25 -0500 Subject: [PATCH] Consistent configuration of veth_pair prefix The veth_pair name was partially configurable, however eth0's veth pair naming scheme was hard coded. This change accomplishes: - veth pair prefix templating is now consistent across all interfaces generated by the role. - no change is made to the default configuration of veth pair naming, it only allows more reusability of the role by allowing the veth pair naming to be configured by the role's consumers. - eth0 veth pair naming scheme can be configured just as other interfaces could be before. Change-Id: I47004126cab85043f623aee8262151d3b53238e9 --- defaults/main.yml | 3 ++- tasks/container_create.yml | 2 +- templates/veth-cleanup.sh.j2 | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 6c809cf..6f501c1 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -114,7 +114,8 @@ lxc_container_download_template_options: > # Toggle the restart of containers via the handler. lxc_container_allow_restarts: yes -lxc_container_network_veth_pair: "{{ inventory_hostname[-8:].replace('-', '').replace('_', '') }}_{{ item.value.interface }}" +lxc_container_network_veth_pair_prefix: "{{ inventory_hostname[-8:].replace('-', '').replace('_', '') }}" +lxc_container_network_veth_pair: "{{ lxc_container_network_veth_pair_prefix }}_{{ item.value.interface }}" # Enable fixed mac address generation for an lxc container lxc_container_fixed_mac: false diff --git a/tasks/container_create.yml b/tasks/container_create.yml index 098d28d..79c4cb9 100644 --- a/tasks/container_create.yml +++ b/tasks/container_create.yml @@ -326,7 +326,7 @@ - name: Add veth pair name to match container name lineinfile: dest: "/var/lib/lxc/{{ inventory_hostname }}/config" - line: "lxc.network.veth.pair = {{ inventory_hostname[-8:].replace('-', '').replace('_', '') }}_eth0" + line: "lxc.network.veth.pair = {{ lxc_container_network_veth_pair_prefix }}_eth0" insertafter: "^lxc.network.name" backup: "true" delegate_to: "{{ physical_host }}" diff --git a/templates/veth-cleanup.sh.j2 b/templates/veth-cleanup.sh.j2 index 6ab4fc0..bd1b32a 100644 --- a/templates/veth-cleanup.sh.j2 +++ b/templates/veth-cleanup.sh.j2 @@ -3,13 +3,13 @@ export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" # LXC eth0 is considered special and not managed by the base container_networks # data structure. This is being added outside of the loop for this reason. -ip link del {{ inventory_hostname[-8:].replace('-', '').replace('_', '') }}_eth0 || true +ip link del {{ lxc_container_network_veth_pair_prefix }}_eth0 || true # Veth cleanup for items in the container_networks data structure {% if container_networks is defined %} {% for key, value in container_networks.items() %} {% if value.type is not defined or value.type == 'veth' %} -ip link del {{ inventory_hostname[-8:].replace('-', '').replace('_', '') }}_{{ value.interface }} || true +ip link del {{ lxc_container_network_veth_pair_prefix }}_{{ value.interface }} || true {% endif %} {% endfor %} {% endif %}