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
This commit is contained in:
Logan V 2017-04-23 20:48:25 -05:00
parent f77cc2fde5
commit 789aaa4e73
3 changed files with 5 additions and 4 deletions

View File

@ -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

View File

@ -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 }}"

View File

@ -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 %}