ansible: fix ci-instances playbook for Incus
[lttng-ci.git] / automation / ansible / roles / lxd / tasks / main.yml
1 ---
2
3 # The core pattern is used by the CI containers
4 - when: ansible_virtualization_role == "host" or (ansible_virtualization_role == "guest" and ansible_virtualization_type == "kvm")
5 block:
6 - name: 'Set core pattern for reboot'
7 ansible.builtin.copy:
8 dest: '/etc/sysctl.d/10-core_pattern.conf'
9 owner: 'root'
10 group: 'root'
11 mode: '0644'
12 content: "kernel.core_pattern /tmp/core.%p\n"
13 - name: 'Check current core pattern'
14 ansible.builtin.command:
15 argv: ['cat', '/proc/sys/kernel/core_pattern']
16 register: current_core_pattern
17 - name: 'Update current core pattern'
18 when: current_core_pattern.stdout|trim != "'{{lxd_core_pattern}}'"
19 ansible.builtin.command:
20 argv: ['sysctl', '-w', "kernel.core_pattern='{{lxd_core_pattern}}'"]
21
22 - name: Install LXD
23 ansible.builtin.apt:
24 name: lxd
25 - name: Ensure LXD service is running
26 ansible.builtin.systemd:
27 name: lxd
28 state: started
29 enabled: true
30 - name: LXD Init
31 block:
32 - ansible.builtin.file:
33 path: /etc/lxd
34 state: directory
35 owner: root
36 group: root
37 mode: '0750'
38 - ansible.builtin.template:
39 dest: /etc/lxd/lxd_init.yml
40 src: init.yaml.j2
41 owner: root
42 group: root
43 mode: '0600'
44 register: lxd_init_template
45 - ansible.builtin.shell:
46 cmd: 'lxd init --preseed=true < /etc/lxd/lxd_init.yml'
47 when: lxd_init_template.changed
48 - name: Check for images volume configuration
49 ansible.builtin.command:
50 argv: ['lxc', 'config', "--target={{lxd_cluster['server_name']|default(ansible_hostname)}}", 'get', 'storage.images_volume']
51 register: images_volume_conf
52 - name: Configure images volume
53 when: images_volume_conf.stdout|trim != "default/storage-images"
54 block:
55 - name: Create volume
56 ansible.builtin.command:
57 argv: ['lxc', 'storage', 'volume', 'create', '--target', "{{lxd_cluster['server_name']|default(ansible_hostname)}}", 'default', 'storage-images']
58 - ansible.builtin.command:
59 argv: ['lxc', 'config', 'set', '--target', "{{lxd_cluster['server_name']|default(ansible_hostname)}}", 'storage.images_volume', 'default/storage-images']
60
61 - name: Check for backups volume configuration
62 ansible.builtin.command:
63 argv: ['lxc', 'config', "--target={{lxd_cluster['server_name']|default(ansible_hostname)}}", 'get', 'storage.backups_volume']
64 register: backups_volume_conf
65 - name: Configure backups volume
66 when: backups_volume_conf.stdout|trim != "default/storage-backups"
67 block:
68 - name: Create volume
69 ansible.builtin.command:
70 argv: ['lxc', 'storage', 'volume', 'create', '--target', "{{lxd_cluster['server_name']|default(ansible_hostname)}}", 'default', 'storage-backups']
71 - ansible.builtin.command:
72 argv: ['lxc', 'config', 'set', '--target', "{{lxd_cluster['server_name']|default(ansible_hostname)}}", 'storage.backups_volume', 'default/storage-backups']
This page took 0.031722 seconds and 5 git commands to generate.