From 761603cf0f19406db7bad442b1f72b40dc46af2f Mon Sep 17 00:00:00 2001 From: Kienan Stewart Date: Wed, 7 Aug 2024 14:03:06 -0400 Subject: [PATCH] ansible: Add minimal role to install incus and incus-tools Change-Id: Ic7026bc40e48b3f46061f8039c8c6ed77fcaac81 Signed-off-by: Kienan Stewart --- .../ansible/roles/incus/defaults/main.yml | 3 ++ .../ansible/roles/incus/tasks/install.yml | 12 +++++ automation/ansible/roles/incus/tasks/main.yml | 49 +++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 automation/ansible/roles/incus/defaults/main.yml create mode 100644 automation/ansible/roles/incus/tasks/install.yml create mode 100644 automation/ansible/roles/incus/tasks/main.yml diff --git a/automation/ansible/roles/incus/defaults/main.yml b/automation/ansible/roles/incus/defaults/main.yml new file mode 100644 index 0000000..a3f17bc --- /dev/null +++ b/automation/ansible/roles/incus/defaults/main.yml @@ -0,0 +1,3 @@ +--- + +incus_core_pattern: '/tmp/core-%p' diff --git a/automation/ansible/roles/incus/tasks/install.yml b/automation/ansible/roles/incus/tasks/install.yml new file mode 100644 index 0000000..aafcd8a --- /dev/null +++ b/automation/ansible/roles/incus/tasks/install.yml @@ -0,0 +1,12 @@ +--- + +- name: Configure bookworm-backports + when: ansible_distribution == 'Debian' and ansible_distribution_major_version == '12' + ansible.builtin.apt_repository: + repo: 'deb https://deb.debian.org/debian bookworm-backports main contrib non-free-firmware' + +- name: Install packages + ansible.builtin.package: + name: + - incus + - incus-tools diff --git a/automation/ansible/roles/incus/tasks/main.yml b/automation/ansible/roles/incus/tasks/main.yml new file mode 100644 index 0000000..10e77a1 --- /dev/null +++ b/automation/ansible/roles/incus/tasks/main.yml @@ -0,0 +1,49 @@ +--- + +- ansible.builtin.include_tasks: + file: install.yml + +# The core pattern is used by the CI containers +- when: ansible_virtualization_role == "host" or (ansible_virtualization_role == "guest" and ansible_virtualization_type == "kvm") + block: + - name: 'Set core pattern for reboot' + ansible.builtin.copy: + dest: '/etc/sysctl.d/10-core_pattern.conf' + owner: 'root' + group: 'root' + mode: '0644' + content: "kernel.core_pattern /tmp/core.%p\n" + - name: 'Check current core pattern' + ansible.builtin.command: + argv: ['cat', '/proc/sys/kernel/core_pattern'] + register: current_core_pattern + - name: 'Update current core pattern' + when: current_core_pattern.stdout|trim != "'{{incus_core_pattern}}'" + ansible.builtin.command: + argv: ['sysctl', '-w', "kernel.core_pattern='{{incus_core_pattern}}'"] + +- name: Check for images volume configuration + ansible.builtin.command: + argv: ['incus', 'config', "--target={{lxd_cluster['server_name']|default(ansible_hostname)}}", 'get', 'storage.images_volume'] + register: images_volume_conf +- name: Configure images volume + when: images_volume_conf.stdout|trim != "default/storage-images" + block: + - name: Create volume + ansible.builtin.command: + argv: ['incus', 'storage', 'volume', 'create', '--target', "{{lxd_cluster['server_name']|default(ansible_hostname)}}", 'default', 'storage-images'] + - ansible.builtin.command: + argv: ['incus', 'config', 'set', '--target', "{{lxd_cluster['server_name']|default(ansible_hostname)}}", 'storage.images_volume', 'default/storage-images'] + +- name: Check for backups volume configuration + ansible.builtin.command: + argv: ['incus', 'config', "--target={{lxd_cluster['server_name']|default(ansible_hostname)}}", 'get', 'storage.backups_volume'] + register: backups_volume_conf +- name: Configure backups volume + when: backups_volume_conf.stdout|trim != "default/storage-backups" + block: + - name: Create volume + ansible.builtin.command: + argv: ['incus', 'storage', 'volume', 'create', '--target', "{{lxd_cluster['server_name']|default(ansible_hostname)}}", 'default', 'storage-backups'] + - ansible.builtin.command: + argv: ['incus', 'config', 'set', '--target', "{{lxd_cluster['server_name']|default(ansible_hostname)}}", 'storage.backups_volume', 'default/storage-backups'] -- 2.34.1