ansible-roles/lxc/tasks/create-container.yml

57 lines
1.6 KiB
YAML

---
- name: Check if container exists
command: "lxc-ls {{name}}"
changed_when: false
register: container_exists
- name: Create container
lxc_container:
name: "{{name}}"
container_log: true
template: debian
state: stopped
template_options: "--arch amd64 --release {{release}}"
- name: Disable network configuration inside container
replace:
name: "/var/lib/lxc/{{name}}/rootfs/etc/default/networking"
regexp: "^#CONFIGURE_INTERFACES=yes"
replace: CONFIGURE_INTERFACES=no
when: lxc_network_type == "none"
- 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 == "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: 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:
name: "/var/lib/lxc/{{name}}/rootfs/etc/hosts"
line: "127.0.0.1 {{name}}"
- name: Fix permission on /dev
lineinfile:
name: "/var/lib/lxc/{{name}}/rootfs/etc/rc.local"
line: "chmod 755 /dev"
insertbefore: "^exit 0$"
when: release == 'jessie'
- name: "Ensure that {{name}} container is running"
lxc_container:
name: "{{name}}"
state: started