lxc: rely on lxc_container module instead of command module

This commit is contained in:
Ludovic Poujol 2019-10-02 16:32:20 +02:00
parent e985f5778c
commit 4aaeb4590b
3 changed files with 26 additions and 24 deletions

View File

@ -40,6 +40,7 @@ The **patch** part changes incrementally at each release.
* varnish: remove custom ExecReload= script for Debian 10+
* lxc: remove useless loop in apt execution
* lxc: update our default template to be compatible with Debian 10
* lxc: rely on lxc_container module instead of command module
### Fixed
* lxc-php: Don't remove the default pool

View File

@ -5,16 +5,12 @@
register: container_exists
- name: Create container
command: "lxc-create --name {{name}} --template debian --bdev dir --logfile /var/log/lxc/lxc-{{name}}.log --logpriority INFO -- --arch amd64 --release {{release}}"
when: container_exists.stdout_lines == []
#- name: Create container
# lxc_container:
# name: "{{name}}"
# container_log: true
# template: download
# state: stopped
# template_options: "--release {{release}}"
lxc_container:
name: "{{name}}"
container_log: true
template: debian
state: stopped
template_options: "--arch amd64 --release {{release}}"
- name: Disable network configuration inside container
replace:
@ -23,21 +19,24 @@
replace: CONFIGURE_INTERFACES=no
when: lxc_network_type == "none"
- name: Disable interface shut down on halt inside container
- name: Disable interface shut down on halt inside container (Jessie container)
lineinfile:
name: "/var/lib/lxc/{{name}}/rootfs/etc/default/halt"
line: "NETDOWN=no"
when: lxc_network_type == "none" and release != "stretch"
when: lxc_network_type == "none" and release == "jessie"
- name: Make the container poweroff on SIGPWR (sent by lxc-stop) on jessie
- name: Make the container poweroff on SIGPWR sent by lxc-stop (Jessie container)
file:
src: /lib/systemd/system/poweroff.target
dest: "/var/lib/lxc/{{name}}/rootfs/etc/systemd/system/sigpwr.target"
state: link
when: release == 'jessie'
- name: Set the DNS resolvers
command: "cp /etc/resolv.conf /var/lib/lxc/{{name}}/rootfs/etc/"
- name: Configure the DNS resolvers in the container
copy:
remote_src: yes
src: /etc/resolv.conf
dest: "/var/lib/lxc/{{name}}/rootfs/etc/"
- name: Add hostname in /etc/hosts
lineinfile:
@ -49,13 +48,9 @@
name: "/var/lib/lxc/{{name}}/rootfs/etc/rc.local"
line: "chmod 755 /dev"
insertbefore: "^exit 0$"
when: release != 'stretch'
when: release == 'jessie'
- name: Check if container is running
command: "lxc-ls --running {{name}}"
changed_when: false
register: container_running
- name: "Start {{name}} container"
command: "lxc-start -dn {{name}}"
when: container_running.stdout_lines == []
- name: "Ensure that {{name}} container is running"
lxc_container:
name: "{{name}}"
state: started

View File

@ -5,6 +5,12 @@
- lxc
- debootstrap
- xz-utils
- python-lxc
- name: Install lxc-templates on Buster
apt:
name: lxc-templates
when: ansible_distribution_major_version | version_compare('10', '>=')
- name: Copy LXC default containers configuration
template: