diff --git a/playbooks/roles/lxc_container_create/tasks/container_create.yml b/playbooks/roles/lxc_container_create/tasks/container_create.yml index 19354ea0ad..8e63bae170 100644 --- a/playbooks/roles/lxc_container_create/tasks/container_create.yml +++ b/playbooks/roles/lxc_container_create/tasks/container_create.yml @@ -187,6 +187,19 @@ tags: - lxc-container-networks +# NOTE(major): the lxc.network.veth.pair line must appear *immediately* after +# the lxc.network.name congfiguration line or it will be ignored. That's why +# you'll find a "insertafter" in this YAML block. +- 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" + insertafter: "^lxc.network.name" + backup: "true" + delegate_to: "{{ physical_host }}" + tags: + - lxc-container-networks + - name: Container network includes lineinfile: dest: "/var/lib/lxc/{{ inventory_hostname }}/config" diff --git a/playbooks/roles/lxc_container_create/templates/container-interface.ini.j2 b/playbooks/roles/lxc_container_create/templates/container-interface.ini.j2 index db2594ca3d..d3f41bddf8 100644 --- a/playbooks/roles/lxc_container_create/templates/container-interface.ini.j2 +++ b/playbooks/roles/lxc_container_create/templates/container-interface.ini.j2 @@ -4,6 +4,10 @@ lxc.network.type = {{ item.value.type|default('veth') }} # Network device within the container lxc.network.name = {{ item.value.interface }} +# Name the veth after the container +# NOTE(major): The lxc.network.veth.pair line must appear right after +# lxc.network.name or it will be ignored. +lxc.network.veth.pair = {{ inventory_hostname[-8:].replace('-', '').replace('_', '') }}_{{ item.value.interface }} # Host link to attach to, this should be a bridge lxc.network.link = {{ item.value.bridge }} # Hardware Address @@ -12,4 +16,3 @@ lxc.network.hwaddr = 00:16:3e:xx:xx:xx lxc.network.flags = up # Set the container network MTU lxc.network.mtu = {{ item.value.mtu|default('1500') }} -