From 4aaeb4590b30d7562518eaee31f283f71eca04db Mon Sep 17 00:00:00 2001 From: Ludovic Poujol Date: Wed, 2 Oct 2019 16:32:20 +0200 Subject: [PATCH] lxc: rely on lxc_container module instead of command module --- CHANGELOG.md | 1 + lxc/tasks/create-container.yml | 43 +++++++++++++++------------------- lxc/tasks/main.yml | 6 +++++ 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21a5c17f..9454b37c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lxc/tasks/create-container.yml b/lxc/tasks/create-container.yml index 6faeeabf..1884d194 100644 --- a/lxc/tasks/create-container.yml +++ b/lxc/tasks/create-container.yml @@ -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 diff --git a/lxc/tasks/main.yml b/lxc/tasks/main.yml index 9dd1ae07..47a4c8bd 100644 --- a/lxc/tasks/main.yml +++ b/lxc/tasks/main.yml @@ -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: