Skip to content

Commit 5ab2c90

Browse files
authored
fix: Fix removing kernel options with values (#146)
* fix: Fix removing kernel options with values * Support Ansible 2.19, rename vars for clarity
1 parent 3d3454a commit 5ab2c90

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

library/bootloader_settings.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,9 @@ def mod_boot_args(module, result, bootloader_setting_options, kernel, kernel_inf
319319
for kernel_setting in bootloader_setting_options:
320320
setting_name = get_setting_name(kernel_setting)
321321
if "state" in kernel_setting and kernel_setting["state"] == "absent":
322-
if re.search(r"(^|$| )" + setting_name + r"(^|$| )", bootloader_args):
322+
if re.search(
323+
r"(^|$| )" + kernel_setting["name"] + r"($| |=)", bootloader_args
324+
):
323325
boot_absent_args += setting_name + " "
324326
else:
325327
if not re.search(r"(^|$| )" + setting_name + r"(^|$| )", bootloader_args):

tests/tests_settings.yml

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,13 @@
6666
value: 1
6767
- name: no_timer_check
6868
state: present
69-
- name: quiet
69+
- name: option_without_value
70+
- name: option_with_value
71+
value: option_value
7072
- previous: replaced
7173
- kernel: ALL
7274
options:
73-
- name: debug
75+
- name: option_set_from_ALL
7476
state: present
7577
bootloader_timeout: 6
7678
include_role:
@@ -89,7 +91,7 @@
8991
(bootloader_facts |
9092
selectattr('index', 'search', cloned_kernel.index) | first).args |
9193
regex_search('^.*console=tty0 print-fatal-signals=1 no_timer_check
92-
quiet debug( |)$')
94+
option_without_value option_with_value=option_value option_set_from_ALL( |)$') | length > 0
9395
9496
- name: Verify boot loader timeout configuration
9597
command: cat {{ __bootloader_grub_conf }}
@@ -106,9 +108,11 @@
106108
- kernel:
107109
title: "{{ cloned_kernel.title }}"
108110
options:
109-
- name: quiet
111+
- name: option_without_value
110112
state: absent
111-
- name: debug
113+
- name: option_set_from_ALL
114+
state: absent
115+
- name: option_with_value
112116
state: absent
113117
bootloader_timeout: 4
114118
include_role:
@@ -121,13 +125,15 @@
121125
assert:
122126
that: not (bootloader_reboot_required | d(false))
123127

124-
- name: Verify settings
128+
- name: Verify that existing settings remained and removed settings are not present
129+
vars:
130+
__settings: "{{ (bootloader_facts | selectattr('index', 'search', cloned_kernel.index) | first).args }}"
125131
assert:
126-
that: >-
127-
(bootloader_facts |
128-
selectattr('index', 'search', cloned_kernel.index) | first).args |
129-
regex_search('^.*console=tty0 print-fatal-signals=1
130-
no_timer_check( |)$')
132+
that:
133+
- __settings | regex_search('^.*console=tty0 print-fatal-signals=1 no_timer_check( |)$') | length > 0
134+
- __settings | regex_search('option_without_value') == none
135+
- __settings | regex_search('option_set_from_ALL') == none
136+
- __settings | regex_search('option_with_value') == none
131137

132138
- name: Verify boot loader timeout configuration
133139
command: cat {{ __bootloader_grub_conf }}
@@ -164,7 +170,7 @@
164170
(bootloader_facts |
165171
selectattr('index', 'search', cloned_kernel.index) | first).args |
166172
regex_search('^.*console=tty0 print-fatal-signals=1
167-
no_timer_check( |)$')
173+
no_timer_check( |)$') | length > 0
168174
169175
- name: Verify boot loader timeout configuration
170176
command: cat {{ __bootloader_grub_conf }}

0 commit comments

Comments
 (0)