From e3620af1c1b49d1efaab0929d7584935270cad6a Mon Sep 17 00:00:00 2001 From: Pierre Riteau Date: Thu, 26 Sep 2024 12:47:52 +0200 Subject: [PATCH] Handle missing GRUB_CMDLINE_LINUX_DEFAULT variable If GRUB_CMDLINE_LINUX_DEFAULT is unset in /etc/default/grub, initialise it from GRUB_CMDLINE_LINUX. We write back the updated kernel command line as GRUB_CMDLINE_LINUX_DEFAULT, the intent being to only apply to normal (non-rescue) boots. However, on RedHat 9.x, the grubby command that runs next still updates GRUB_CMDLINE_LINUX. Fixes #18. --- roles/grubcmdline/tasks/main.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/roles/grubcmdline/tasks/main.yml b/roles/grubcmdline/tasks/main.yml index 751175e..33414d3 100644 --- a/roles/grubcmdline/tasks/main.yml +++ b/roles/grubcmdline/tasks/main.yml @@ -26,10 +26,24 @@ grub_cmdline_linux_default: >- {{ grub_result.content | b64decode | regex_search('^GRUB_CMDLINE_LINUX_DEFAULT.*$', multiline=True) | regex_replace('^GRUB_CMDLINE_LINUX_DEFAULT="(.*)"$', '\1') }} +- name: Set fact containing GRUB_CMDLINE_LINUX + ansible.builtin.set_fact: + grub_cmdline_linux: >- + {{ grub_result.content | b64decode | regex_search('^GRUB_CMDLINE_LINUX=.*$', multiline=True) | regex_replace('^GRUB_CMDLINE_LINUX="(.*)"$', '\1') }} + - name: Display GRUB_CMDLINE_LINUX_DEFAULT ansible.builtin.debug: var: grub_cmdline_linux_default +- name: Display GRUB_CMDLINE_LINUX + ansible.builtin.debug: + var: grub_cmdline_linux + +- name: Initialise GRUB_CMDLINE_LINUX_DEFAULT if unset + ansible.builtin.set_fact: + grub_cmdline_linux_default: "{{ grub_cmdline_linux }}" + when: grub_cmdline_linux_default == 'None' + - name: Determine which parameters need removing # We use a regex here so you can remove parameters regardless of their value, e.g to remove iommu=on you # could use the regex: ^iommu=