-
Notifications
You must be signed in to change notification settings - Fork 14
feat: Argument spec implementation dszabo #239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DonatSzabo
wants to merge
2
commits into
linux-system-roles:main
Choose a base branch
from
DonatSzabo:argument_spec_implementation-dszabo
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| # SPDX-License-Identifier: MIT | ||
| --- | ||
| argument_specs: | ||
| main: | ||
| short_description: The bootloader role. | ||
| description: > | ||
| The bootloader role allows you to manage GRUB2 boot loader | ||
| settings, kernel command line parameters, boot loader | ||
| timeout, and boot loader password. | ||
| options: | ||
| bootloader_settings: | ||
| type: list | ||
| elements: dict | ||
| default: [] | ||
| description: > | ||
| List of kernel entries and their command line parameters | ||
| to configure. Each entry specifies a kernel and the | ||
| boot loader settings to apply. | ||
| options: | ||
| kernel: | ||
| type: raw | ||
| required: true | ||
| description: > | ||
| The kernel to update settings for. Accepts the | ||
| string `DEFAULT` or `ALL` to target the default or | ||
| all kernels, or a dictionary with keys `path`, | ||
| `index`, `title`, and `initrd` to identify a | ||
| specific kernel. | ||
| state: | ||
| type: str | ||
| choices: | ||
| - present | ||
| - absent | ||
| default: present | ||
| description: > | ||
| Whether the kernel entry should be present | ||
| (`present`) or removed (`absent`). | ||
| options: | ||
| type: list | ||
| elements: dict | ||
| description: > | ||
| List of boot loader arguments to apply to the | ||
| specified kernel. | ||
| options: | ||
| name: | ||
| type: str | ||
| description: > | ||
| The name of the boot loader setting. Not | ||
| required when using `previous: replaced`. | ||
| value: | ||
| type: raw | ||
| description: > | ||
| The value for the setting. Not required when | ||
| the setting has no value, for example `quiet`. | ||
| The value must not be a YAML boolean or null | ||
| type. | ||
| state: | ||
| type: str | ||
| choices: | ||
| - present | ||
| - absent | ||
| default: present | ||
| description: > | ||
| Whether the setting should be present | ||
| (`present`) or removed (`absent`). The value | ||
| `absent` removes the setting with the given | ||
| `name`. | ||
| previous: | ||
| type: str | ||
| choices: | ||
| - replaced | ||
| description: > | ||
| Whether to replace all previous settings with | ||
| the given settings. The only supported value | ||
| is `replaced`. | ||
| copy_default: | ||
| type: bool | ||
| default: false | ||
| description: > | ||
| Whether to copy the default arguments to the | ||
| created kernel. | ||
| default: | ||
| type: bool | ||
| default: false | ||
| description: > | ||
| Whether to make this kernel the default boot | ||
| entry. | ||
|
|
||
| bootloader_timeout: | ||
| type: raw | ||
| default: null | ||
| description: > | ||
| The GRUB boot loader timeout in seconds. When set to | ||
| `null` or left unset, the role does not change the | ||
| timeout setting. | ||
|
|
||
| bootloader_password: | ||
| type: raw | ||
| default: null | ||
| description: > | ||
| The password to protect boot parameters. When set to | ||
| `null` or left unset, the current password | ||
| configuration is not modified. The boot loader | ||
| username is always `root`. This value should come | ||
| from an Ansible vault. | ||
|
|
||
| bootloader_remove_password: | ||
| type: bool | ||
| default: false | ||
| description: > | ||
| Whether to remove the boot loader password | ||
| configuration. | ||
|
|
||
| bootloader_reboot_ok: | ||
| type: bool | ||
| default: false | ||
| description: > | ||
| Whether the role is allowed to reboot the managed host | ||
| when changes require a reboot to take effect. If | ||
| `false`, the role sets `bootloader_reboot_required` to | ||
| `true` instead. | ||
|
|
||
| bootloader_gather_facts: | ||
| type: bool | ||
| default: false | ||
| description: > | ||
| Whether to gather bootloader facts containing boot | ||
| information for all kernels. The facts are returned | ||
| in the `bootloader_facts` variable. | ||
|
|
||
| bootloader_secure_logging: | ||
| type: bool | ||
| default: true | ||
| description: > | ||
| Whether to suppress potentially sensitive output from | ||
| tasks that handle credentials by setting `no_log` to | ||
| `true` on those tasks. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # SPDX-License-Identifier: MIT | ||
| --- | ||
| - name: Assert bootloader_timeout is null or a non-negative integer | ||
| ansible.builtin.assert: | ||
| that: | ||
| - >- | ||
| (bootloader_timeout is none) | ||
| or (bootloader_timeout | string | trim is match('^[0-9]+$')) | ||
| fail_msg: >- | ||
| bootloader_timeout must be null or a non-negative integer, | ||
| got {{ bootloader_timeout | type_debug }} | ||
|
|
||
| - name: Assert bootloader_password is null or a string | ||
| ansible.builtin.assert: | ||
| that: | ||
| - >- | ||
| (bootloader_password is none) | ||
| or (bootloader_password is string) | ||
| fail_msg: >- | ||
| bootloader_password must be null or a string, | ||
| got {{ bootloader_password | type_debug }} | ||
|
|
||
| - name: Assert kernel in bootloader_settings is a string or dictionary | ||
| ansible.builtin.assert: | ||
| that: | ||
| - >- | ||
| item.kernel is string | ||
| or item.kernel is mapping | ||
| fail_msg: >- | ||
| bootloader_settings[{{ idx }}].kernel must be a string | ||
| or dictionary, got {{ item.kernel | type_debug }} | ||
| loop: "{{ bootloader_settings }}" | ||
| loop_control: | ||
| index_var: idx | ||
| label: "{{ idx }}" | ||
| when: item.kernel is defined | ||
|
|
||
| - name: Assert value in bootloader_settings options is a string or integer | ||
| ansible.builtin.assert: | ||
| that: | ||
| - >- | ||
| item.1.value is string | ||
| or (item.1.value | type_debug) == 'int' | ||
| fail_msg: >- | ||
| bootloader_settings options value must be a string | ||
| or integer, got {{ item.1.value | type_debug }} | ||
| loop: >- | ||
| {{ bootloader_settings | subelements('options', skip_missing=True) }} | ||
| loop_control: | ||
| label: "{{ item.0.kernel | default('unknown') }} - {{ item.1.name | default('unnamed') }}" | ||
| when: item.1.value is defined and item.1.value is not none | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Reject settings entries without
kernel.Line 36 skips this assertion when
kernelis absent. On paths where argument specifications are not applied, the malformed entry reaches bootloader configuration without required-field validation. Assert thatitem.kernelis defined before checking its type.Proposed fix
ansible.builtin.assert: that: - - >- - item.kernel is string - or item.kernel is mapping + - item.kernel is defined + - item.kernel is string or item.kernel is mapping fail_msg: >- bootloader_settings[{{ idx }}].kernel must be a string - or dictionary, got {{ item.kernel | type_debug }} + or dictionary, got {{ item.kernel | default(none) | type_debug }} loop: "{{ bootloader_settings }}" - when: item.kernel is defined📝 Committable suggestion
🤖 Prompt for AI Agents