ansible: Add minimal role to install incus and incus-tools
authorKienan Stewart <kstewart@efficios.com>
Wed, 7 Aug 2024 18:03:06 +0000 (14:03 -0400)
committerKienan Stewart <kstewart@efficios.com>
Thu, 8 Aug 2024 18:19:47 +0000 (14:19 -0400)
Change-Id: Ic7026bc40e48b3f46061f8039c8c6ed77fcaac81
Signed-off-by: Kienan Stewart <kstewart@efficios.com>
automation/ansible/roles/incus/defaults/main.yml [new file with mode: 0644]
automation/ansible/roles/incus/tasks/install.yml [new file with mode: 0644]
automation/ansible/roles/incus/tasks/main.yml [new file with mode: 0644]

diff --git a/automation/ansible/roles/incus/defaults/main.yml b/automation/ansible/roles/incus/defaults/main.yml
new file mode 100644 (file)
index 0000000..a3f17bc
--- /dev/null
@@ -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 (file)
index 0000000..aafcd8a
--- /dev/null
@@ -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 (file)
index 0000000..10e77a1
--- /dev/null
@@ -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']
This page took 0.024038 seconds and 4 git commands to generate.