Skip to content

Commit 9538870

Browse files
committed
fix: boolean values and null values are not allowed
Cause: The user could specify a value like `value: on` or `value: yes` thinking that these would be converted to the string `"on"` or `"yes"`. But instead, YAML treats these as [YAML bool type](https://yaml.org/type/bool.html) and writes them as the string `"True"`. Consequence: The user who is unaware of YAML boolean handling is not able to set values to `"on"`, `"off"`, or the like. Fix: The role will reject any value of boolean or `null` type. Result: Users must quote such YAML boolean type values as strings in order to write them to the bootloader configuration. Signed-off-by: Rich Megginson <rmeggins@redhat.com>
1 parent c672ee7 commit 9538870

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ Each entry should specify a kernel using one or more keys.
7777

7878
* `name` - The name of the setting. Omit `name` when using `replaced`.
7979
* `value` - The value for the setting. You must omit `value` if the setting has no value, e.g. `quiet`.
80+
**NOTE** - a value must not be [YAML bool type](https://yaml.org/type/bool.html).
81+
One situation where this might be a problem is using `value: on` or other
82+
YAML `bool` typed value. You must quote these values, or otherwise pass
83+
them as a value of `str` type e.g. `value: "on"`. The same applies to `null` values.
84+
If you specify a value, it must not be `null` - values such as `value:` or `value: ~`
85+
or `value: null` are not allowed and will raise an error.
8086
* `state` - `present` (default) or `absent`. The value `absent` means to remove a setting with the given `name` - the name must be provided.
8187
* `previous` - Optional - the only supported value is `replaced` - use this to specify that the previous settings should be replaced with the given settings.
8288
* `copy_default` - Optional - when creating a kernel, you can specify `copy_default: true` to copy the default arguments to the created kernel.

tasks/main.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,24 @@
1010
Let us know if you need the role to support it.
1111
when: ansible_architecture == 's390x'
1212

13+
# null is allowed as a value for state: absent - but it is not needed
14+
# and should not be used
15+
- name: Check bootloader settings for boolean and null values
16+
fail:
17+
msg: Boolean and null values are not allowed for bootloader settings
18+
when:
19+
- (__values | selectattr("value", "sameas", true) | list | length > 0) or
20+
(__values | selectattr("value", "sameas", false) | list | length > 0) or
21+
(__values_with_null_and_state_present | length > 0) or
22+
(__values_with_null_and_no_state | length > 0)
23+
vars:
24+
__values: "{{ bootloader_settings | selectattr('options', 'defined') |
25+
map(attribute='options') | flatten | selectattr('value', 'defined') | list }}"
26+
__values_with_null_and_state_present: "{{ __values | selectattr('state', 'defined') |
27+
selectattr('state', 'match', 'present$') | selectattr('value', 'sameas', none) | list }}"
28+
__values_with_null_and_no_state: "{{ __values | rejectattr('state', 'defined') |
29+
selectattr('value', 'sameas', none) | list }}"
30+
1331
- name: Ensure required packages are installed
1432
package:
1533
name: "{{ __bootloader_packages }}"

0 commit comments

Comments
 (0)