From 031314863c129efb5259c9cde405a96774697b4c Mon Sep 17 00:00:00 2001 From: James Osborne Date: Mon, 22 Jan 2024 13:49:54 +0000 Subject: [PATCH 1/2] Handle emptry list items Add `select()` filter to the creation of `grub_cmdline_linux_new` removes empty list elements, which for example might exist in `kernal_cmdline` as a result of defaults. --- roles/grubcmdline/tasks/main.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/roles/grubcmdline/tasks/main.yml b/roles/grubcmdline/tasks/main.yml index f2f12d8..e8d29b1 100644 --- a/roles/grubcmdline/tasks/main.yml +++ b/roles/grubcmdline/tasks/main.yml @@ -1,4 +1,3 @@ ---- - name: Check current kernel command line args ansible.builtin.command: cat /proc/cmdline register: result @@ -23,9 +22,7 @@ - name: Set fact containing GRUB_CMDLINE_LINUX_DEFAULT ansible.builtin.set_fact: grub_cmdline_linux_default: >- - {{ grub_result.content | b64decode | regex_search('^GRUB_CMDLINE_LINUX_DEFAULT.*$', multiline=True) - | regex_replace('^GRUB_CMDLINE_LINUX_DEFAULT="(.*)"$', '\1') }} - + {{ grub_result.content | b64decode | regex_search('^GRUB_CMDLINE_LINUX_DEFAULT.*$', multiline=True) | regex_replace('^GRUB_CMDLINE_LINUX_DEFAULT="(.*)"$', '\1') }} #magic___^_^___line - name: Display GRUB_CMDLINE_DEFAULT ansible.builtin.debug: var: grub_cmdline_linux_default @@ -42,7 +39,7 @@ - name: Updated kernel cmd line params ansible.builtin.set_fact: - grub_cmdline_linux_new: "{{ grub_cmdline_linux_default.split() | difference(grub_cmdline_linux_remove) + kernel_cmdline }}" + grub_cmdline_linux_new: "{{ grub_cmdline_linux_default.split() | difference(grub_cmdline_linux_remove) + kernel_cmdline | select() }}" - name: Display newly computed GRUB_CMDLINE_DEFAULT ansible.builtin.debug: From 2cb415a7164f78134a61a7efab48570122949005 Mon Sep 17 00:00:00 2001 From: James Osborne Date: Tue, 23 Jan 2024 11:47:33 +0000 Subject: [PATCH 2/2] Changes requested on PR --- roles/grubcmdline/tasks/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/roles/grubcmdline/tasks/main.yml b/roles/grubcmdline/tasks/main.yml index e8d29b1..46584d7 100644 --- a/roles/grubcmdline/tasks/main.yml +++ b/roles/grubcmdline/tasks/main.yml @@ -1,3 +1,4 @@ +--- - name: Check current kernel command line args ansible.builtin.command: cat /proc/cmdline register: result @@ -22,7 +23,7 @@ - name: Set fact containing GRUB_CMDLINE_LINUX_DEFAULT ansible.builtin.set_fact: grub_cmdline_linux_default: >- - {{ grub_result.content | b64decode | regex_search('^GRUB_CMDLINE_LINUX_DEFAULT.*$', multiline=True) | regex_replace('^GRUB_CMDLINE_LINUX_DEFAULT="(.*)"$', '\1') }} #magic___^_^___line + {{ grub_result.content | b64decode | regex_search('^GRUB_CMDLINE_LINUX_DEFAULT.*$', multiline=True) | regex_replace('^GRUB_CMDLINE_LINUX_DEFAULT="(.*)"$', '\1') }} - name: Display GRUB_CMDLINE_DEFAULT ansible.builtin.debug: var: grub_cmdline_linux_default