aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/roles/kernel/tasks
diff options
context:
space:
mode:
Diffstat (limited to 'roles/kernel/tasks')
-rw-r--r--roles/kernel/tasks/grub.yml33
-rw-r--r--roles/kernel/tasks/main.yml38
-rw-r--r--roles/kernel/tasks/systemd-boot.yml53
3 files changed, 124 insertions, 0 deletions
diff --git a/roles/kernel/tasks/grub.yml b/roles/kernel/tasks/grub.yml
new file mode 100644
index 0000000..bcf83e2
--- /dev/null
+++ b/roles/kernel/tasks/grub.yml
@@ -0,0 +1,33 @@
+- name: Set default GRUB entry
+ vars:
+ kernel_image: |
+ {{
+ {
+ 'latest': '/boot/vmlinuz-linux',
+ 'lts': '/boot/vmlinuz-linux-lts',
+ }[kernel_flavour]
+ }}
+ become: true
+ community.general.ini_file:
+ create: false
+ ignore_spaces: true
+ no_extra_spaces: true
+ path: /etc/default/grub
+ option: GRUB_TOP_LEVEL
+ value: '{{ kernel_image }}'
+
+- name: Generate GRUB config
+ become: true
+ ansible.builtin.command: grub-mkconfig
+ changed_when: false
+ register: kernel_mkconfig
+
+- name: Update grub.cfg
+ become: true
+ ansible.builtin.copy:
+ content: '{{ kernel_mkconfig.stdout }}'
+ dest: /boot/grub/grub.cfg
+ owner: root
+ group: root
+ mode: '0755'
+ notify: bootloader_configured
diff --git a/roles/kernel/tasks/main.yml b/roles/kernel/tasks/main.yml
new file mode 100644
index 0000000..923cb98
--- /dev/null
+++ b/roles/kernel/tasks/main.yml
@@ -0,0 +1,38 @@
+- name: Get distro
+ ansible.builtin.setup:
+ gather_subset:
+ - distribution
+
+- name: Fail unless Arch Linux
+ when: |
+ ansible_facts['distribution'] != 'Archlinux'
+ ansible.builtin.fail:
+ msg: Only works on Arch Linux
+
+- name: Fail if wrong flavour
+ when: |
+ kernel_flavour not in ['latest', 'lts']
+ ansible.builtin.fail:
+ msg: Kernel flavour must be either 'latest' or 'lts'
+
+- name: Install kernels
+ become: true
+ ansible.builtin.package:
+ name:
+ - linux
+ - linux-headers
+ - linux-lts
+ - linux-lts-headers
+
+- name: Fail if invalid bootloader
+ when: |
+ kernel_bootloader not in ['grub', 'systemd-boot']
+ ansible.builtin.fail:
+ msg: |
+ Supported bootloaders are: 'grub', 'systemd-boot'
+
+- name: 'Set up for bootloader {{ kernel_bootloader }}'
+ ansible.builtin.include_tasks: '{{ kernel_bootloader }}.yml'
+
+- name: Run handlers if neccessary
+ ansible.builtin.meta: flush_handlers
diff --git a/roles/kernel/tasks/systemd-boot.yml b/roles/kernel/tasks/systemd-boot.yml
new file mode 100644
index 0000000..2f40163
--- /dev/null
+++ b/roles/kernel/tasks/systemd-boot.yml
@@ -0,0 +1,53 @@
+- name: Get default command line options
+ ansible.builtin.setup:
+ gather_subset:
+ - cmdline
+
+- name: Current command line
+ ansible.builtin.debug:
+ var: |
+ ansible_facts['cmdline']
+
+- name: Validate command line
+ loop:
+ - root
+ - rw
+ when: item not in ansible_facts['cmdline']
+ ansible.builtin.fail:
+ msg:
+ Expected option {{ item }} was not found in the current config!
+
+- name: Generate bootloader entries
+ loop:
+ - latest
+ - lts
+ loop_control:
+ loop_var: flavour
+ become: true
+ ansible.builtin.template:
+ src: loader.conf
+ dest: '/boot/loader/entries/{{ flavour }}.conf'
+ owner: root
+ group: root
+ mode: '0600'
+ notify: bootloader_configured
+
+- name: Set default entry
+ become: true
+ ansible.builtin.lineinfile:
+ path: /boot/loader/loader.conf
+ regexp: '^default '
+ line: 'default {{ kernel_flavour }}.conf'
+ owner: root
+ group: root
+ mode: '0600'
+ notify: bootloader_configured
+
+- name: Remove archinstall entries
+ when: kernel_systemd_boot_purge_archinstall
+ become: true
+ community.general.file_remove:
+ path: /boot/loader/entries
+ pattern: '\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}_linux.conf'
+ use_regex: true
+ notify: bootloader_configured