2017-08-22 17:32:32 +02:00
|
|
|
---
|
2019-10-21 15:23:37 +02:00
|
|
|
- name: "Check if container {{ name }} exists"
|
2023-03-20 23:33:19 +01:00
|
|
|
ansible.builtin.command:
|
|
|
|
cmd: "lxc-ls {{ name }}"
|
2023-03-16 14:35:12 +01:00
|
|
|
changed_when: False
|
2020-04-08 17:57:46 +02:00
|
|
|
check_mode: no
|
2017-08-22 17:32:32 +02:00
|
|
|
register: container_exists
|
|
|
|
|
2019-10-21 15:23:37 +02:00
|
|
|
- name: "Create container {{ name }}"
|
2023-03-20 23:33:19 +01:00
|
|
|
community.general.lxc_container:
|
2020-04-17 15:56:54 +02:00
|
|
|
name: "{{ name }}"
|
2019-10-02 16:32:20 +02:00
|
|
|
container_log: true
|
|
|
|
template: debian
|
|
|
|
state: stopped
|
2020-04-17 15:56:54 +02:00
|
|
|
template_options: "--arch amd64 --release {{ release }}"
|
2022-12-14 07:38:04 +01:00
|
|
|
when: container_exists.stdout_lines | length == 0
|
2019-06-17 10:52:20 +02:00
|
|
|
|
2019-10-21 15:23:37 +02:00
|
|
|
- name: "Disable network configuration inside container {{ name }}"
|
2023-03-20 23:33:19 +01:00
|
|
|
ansible.builtin.replace:
|
2020-04-17 15:56:54 +02:00
|
|
|
name: "/var/lib/lxc/{{ name }}/rootfs/etc/default/networking"
|
2017-08-22 17:32:32 +02:00
|
|
|
regexp: "^#CONFIGURE_INTERFACES=yes"
|
|
|
|
replace: CONFIGURE_INTERFACES=no
|
2022-12-14 07:38:04 +01:00
|
|
|
when: lxc_network_type == "none"
|
2017-08-22 17:32:32 +02:00
|
|
|
|
2019-10-21 15:23:37 +02:00
|
|
|
- name: "Disable interface shut down on halt inside container {{ name }} (Jessie container)"
|
2023-03-20 23:33:19 +01:00
|
|
|
ansible.builtin.lineinfile:
|
2020-04-17 15:56:54 +02:00
|
|
|
name: "/var/lib/lxc/{{ name }}/rootfs/etc/default/halt"
|
2017-08-22 17:32:32 +02:00
|
|
|
line: "NETDOWN=no"
|
2022-12-14 07:38:04 +01:00
|
|
|
when: lxc_network_type == "none" and release == "jessie"
|
2017-08-22 17:32:32 +02:00
|
|
|
|
2019-10-21 15:23:37 +02:00
|
|
|
- name: "Make the container {{ name }} poweroff on SIGPWR sent by lxc-stop (Jessie container)"
|
2023-03-20 23:33:19 +01:00
|
|
|
ansible.builtin.file:
|
2017-08-22 17:32:32 +02:00
|
|
|
src: /lib/systemd/system/poweroff.target
|
2020-04-17 15:56:54 +02:00
|
|
|
dest: "/var/lib/lxc/{{ name }}/rootfs/etc/systemd/system/sigpwr.target"
|
2017-08-22 17:32:32 +02:00
|
|
|
state: link
|
|
|
|
when: release == 'jessie'
|
|
|
|
|
2019-10-21 15:23:37 +02:00
|
|
|
- name: "Configure the DNS resolvers in the container {{ name }}"
|
2023-03-20 23:33:19 +01:00
|
|
|
ansible.builtin.copy:
|
2019-10-02 16:32:20 +02:00
|
|
|
remote_src: yes
|
|
|
|
src: /etc/resolv.conf
|
2020-04-17 15:56:54 +02:00
|
|
|
dest: "/var/lib/lxc/{{ name }}/rootfs/etc/"
|
2017-08-22 17:32:32 +02:00
|
|
|
|
2019-10-21 15:23:37 +02:00
|
|
|
- name: "Add hostname in /etc/hosts for container {{ name }}"
|
2023-03-20 23:33:19 +01:00
|
|
|
ansible.builtin.lineinfile:
|
2020-04-17 15:56:54 +02:00
|
|
|
name: "/var/lib/lxc/{{ name }}/rootfs/etc/hosts"
|
|
|
|
line: "127.0.0.1 {{ name }}"
|
2017-08-22 17:32:32 +02:00
|
|
|
|
2019-10-21 15:23:37 +02:00
|
|
|
- name: "Fix permission on /dev for container {{ name }}"
|
2023-03-20 23:33:19 +01:00
|
|
|
ansible.builtin.lineinfile:
|
2020-04-17 15:56:54 +02:00
|
|
|
name: "/var/lib/lxc/{{ name }}/rootfs/etc/rc.local"
|
2017-08-22 17:32:32 +02:00
|
|
|
line: "chmod 755 /dev"
|
|
|
|
insertbefore: "^exit 0$"
|
2022-12-14 07:38:04 +01:00
|
|
|
when: release == 'jessie'
|
2017-08-22 17:32:32 +02:00
|
|
|
|
2020-04-17 15:56:54 +02:00
|
|
|
- name: "Ensure that {{ name }} container is running"
|
2023-03-20 23:33:19 +01:00
|
|
|
community.general.lxc_container:
|
2020-04-17 15:56:54 +02:00
|
|
|
name: "{{ name }}"
|
2019-10-02 16:32:20 +02:00
|
|
|
state: started
|
2023-03-08 11:09:36 +01:00
|
|
|
|
|
|
|
- name: "Ensure /etc/profile.d exists in container"
|
|
|
|
ansible.builtin.file:
|
|
|
|
path: "/var/lib/lxc/{{ name }}/rootfs/etc/profile.d"
|
|
|
|
mode: '0755'
|
|
|
|
state: directory
|
|
|
|
|
|
|
|
- name: "Copy host /etc/profile.d/evolinux into container"
|
|
|
|
ansible.builtin.copy:
|
|
|
|
src: "/etc/profile.d/evolinux.sh"
|
|
|
|
remote_src: true
|
|
|
|
dest: "/var/lib/lxc/{{ name }}/rootfs/etc/profile.d/evolinux.sh"
|