Reorder lxc networking tasks

Drop the lxc bridge interface configuration file before checking for,
and bringing up, the lxc bridge interface. Also, put the
lxc-net.override file in place prior to lxc being installed. Without
this file, the lxcbr0 bridge will automatically be created and assigned
an address when the lxc service is started.

Tests has been added and updated to ensure that the lxc bridge interface
configuration file looks as expected and the bridge interface itself
has the expected IP address when overriding the role's default
lxc_net_address variable.

Change-Id: Ie135adf0e458bd964c2d43a645d65907c0a6eac6
This commit is contained in:
Jimmy McCrory 2016-03-05 21:19:55 -08:00
parent 082cc119dc
commit ad8908a153
5 changed files with 30 additions and 14 deletions

View File

@ -22,6 +22,18 @@
- lxc-net
- lxc-interfaces
- name: Drop lxc net bridge
template:
src: "lxc-net-bridge.cfg.j2"
dest: "/etc/network/interfaces.d/lxc-net-bridge.cfg"
owner: "root"
group: "root"
mode: "0644"
tags:
- lxc-files
- lxc-net
- lxc-bridge
- name: Check Container Bridge exists
file:
state: "file"
@ -34,15 +46,3 @@
tags:
- lxc-net
- lxc-bridge
- name: Drop lxc net bridge
template:
src: "lxc-net-bridge.cfg.j2"
dest: "/etc/network/interfaces.d/lxc-net-bridge.cfg"
owner: "root"
group: "root"
mode: "0644"
tags:
- lxc-files
- lxc-net
- lxc-bridge

View File

@ -34,7 +34,6 @@
- { src: lxc-openstack.conf.j2, dest: "/etc/lxc/lxc-openstack.conf" }
- { src: lxc.default.j2, dest: "/etc/default/lxc-net", mode: "0644" }
- { src: lxc-system-manage.j2, dest: "/usr/local/bin/lxc-system-manage", mode: "0755" }
- { src: manual-init.override.j2, dest: "/etc/init/lxc-net.override" }
tags:
- lxc-files
- lxc-config

View File

@ -32,3 +32,14 @@
- "{{ lxc_container_cache_path }}"
tags:
- lxc-directories
- name: Drop lxc-net override file
template:
src: manual-init.override.j2
dest: /etc/init/lxc-net.override
owner: root
group: root
mode: 0644
tags:
- lxc-files
- lxc-config

View File

@ -1,6 +1,6 @@
auto lxcbr0
iface lxcbr0 inet static
address 10.0.3.1
address 10.100.100.1
netmask 255.255.255.0
# dnsmasq start and stop
post-up /usr/local/bin/lxc-system-manage iptables-create

View File

@ -33,6 +33,7 @@
lxc_container_ssh_key: key_get.stdout
roles:
- role: "{{ rolename | basename }}"
lxc_net_address: 10.100.100.1
lxc_net_bridge: lxcbr0
lxc_kernel_options:
- { key: 'fs.inotify.max_user_instances', value: 1024 }
@ -71,6 +72,10 @@
shell: |
cat files/expected-lxc-net-bridge.cfg
register: expected_interface_file
- name: Get bridge interface facts
setup:
filter: ansible_lxcbr0
register: lxcbr0_facts
- name: Check role functions
assert:
that:
@ -79,3 +84,4 @@
- "container_cache_dir.stat.isdir"
- "container_tar_file.stat.exists"
- "interface_file.stdout | match(expected_interface_file.stdout)"
- "lxcbr0_facts.ansible_facts.ansible_lxcbr0.ipv4.address | match('10.100.100.1')"