diff --git a/defaults/main.yml b/defaults/main.yml index 6c809cf9..6f501c17 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 098d28d7..79c4cb95 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 6ab4fc04..bd1b32aa 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 %}