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+ * varnish: remove custom ExecReload= script for Debian 10+
* lxc: remove useless loop in apt execution * lxc: remove useless loop in apt execution
* lxc: update our default template to be compatible with Debian 10 * lxc: update our default template to be compatible with Debian 10
* lxc: rely on lxc_container module instead of command module
### Fixed ### Fixed
* lxc-php: Don't remove the default pool * lxc-php: Don't remove the default pool

View file

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

View file

@ -5,6 +5,12 @@
- lxc - lxc
- debootstrap - debootstrap
- xz-utils - 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 - name: Copy LXC default containers configuration
template: template: