-
Notifications
You must be signed in to change notification settings - Fork 21
feat: Argument spec implementation for ssh role #267
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,117 @@ | ||
| # SPDX-License-Identifier: MIT | ||
| --- | ||
| argument_specs: | ||
| main: | ||
| short_description: The ssh role. | ||
| description: > | ||
| The ssh role allows you to configure the OpenSSH client, either | ||
| system-wide, using a drop-in configuration file, or for a | ||
| specific user. | ||
|
|
||
| This role installs the required packages and generates an SSH | ||
| client configuration file from the options given in `ssh`, | ||
| including any `Match` and `Host` conditional blocks. Individual | ||
| `ssh_<OptionName>` variables (such as `ssh_ForwardX11`) are also | ||
| supported and override the corresponding key in `ssh`. | ||
| options: | ||
| ssh_user: | ||
| type: str | ||
| default: null | ||
| description: > | ||
| Whether to manage the global SSH client configuration or a | ||
| single user's configuration. When `null`, the role manages | ||
| the system-wide configuration. Otherwise, this is the name | ||
| of a user whose per-user configuration file | ||
| (`~/.ssh/config`) will be managed. The user must already | ||
| exist on the managed host. | ||
| ssh_skip_defaults: | ||
| type: raw | ||
| default: auto | ||
| description: > | ||
| Whether the generated configuration file keeps the OS | ||
| default values for options that are not explicitly set. | ||
| Accepts `true` to keep OS defaults, `false` to omit them, | ||
| or `auto` to let the role decide: defaults are omitted when | ||
| writing a drop-in file or a per-user configuration file, and | ||
| kept otherwise. | ||
| ssh_drop_in_name: | ||
| type: str | ||
| default: null | ||
| description: > | ||
| The name used to build the path of the drop-in | ||
| configuration file placed in the system-wide SSH client | ||
| drop-in directory, following the template | ||
| `/etc/ssh/ssh_config.d/{name}.conf`. The suggested format is | ||
| `NN-name`, where `NN` is a two-digit number used for | ||
| sorting. Ignored on platforms that do not support a drop-in | ||
| directory. | ||
| ssh: | ||
| type: raw | ||
| default: [] | ||
| description: > | ||
| A dict of SSH client configuration options and their | ||
| values, keyed by the option name as documented in | ||
| `ssh_config(5)`, such as `Compression`, `ControlMaster`, | ||
| `GSSAPIAuthentication`, or `Ciphers`. A value can be a | ||
| boolean, a string, a number, or a list of strings, depending | ||
| on the option. The special keys `Match` and `Host` accept a | ||
| single dict or a list of dicts describing conditional | ||
| configuration blocks; each dict must contain a `Condition` | ||
| key plus any of the same option keys, and is rendered as a | ||
| `Match <Condition>` or `Host <Condition>` block. Accepts an | ||
| empty list when no options are being set. | ||
| ssh_additional_packages: | ||
| type: list | ||
| elements: str | ||
| default: [] | ||
| description: > | ||
| List of extra package names to install in addition to the | ||
| packages the role installs automatically, such as | ||
| `openssh-keysign` or `openssh-askpass`, needed for less | ||
| common use cases like host-based authentication. | ||
| ssh_config_owner: | ||
| type: str | ||
| default: null | ||
| description: > | ||
| The user name or user id that owns the generated | ||
| configuration file. When unset, ownership defaults to the | ||
| value of `ssh_user`, or `root` when `ssh_user` is not set. | ||
| ssh_config_group: | ||
| type: str | ||
| default: null | ||
| description: > | ||
| The group name or group id that owns the generated | ||
| configuration file. When unset, group ownership defaults to | ||
| the value of `ssh_user`, or `root` when `ssh_user` is not | ||
| set. | ||
| ssh_config_mode: | ||
| type: raw | ||
| default: null | ||
| description: > | ||
| The file system permissions for the generated configuration | ||
| file. Accepts a string (such as `'0644'`) or an integer. | ||
| When unset, mode defaults to `0600` for per-user | ||
| configuration or `0644` for system-wide configuration. | ||
| ssh_config_file: | ||
| type: path | ||
| default: null | ||
| description: > | ||
| The path of the configuration file that will be written by | ||
| the role. When unset, the path is derived from | ||
| `ssh_drop_in_name` and `ssh_user`. | ||
| ssh_backup: | ||
| type: bool | ||
| default: true | ||
| description: > | ||
| Whether to create a backup of the existing configuration | ||
| file before overwriting it. | ||
| ssh_transactional_update_reboot_ok: | ||
| type: raw | ||
| default: null | ||
| description: > | ||
| Whether to allow a reboot required by transactional update | ||
| systems after installing packages. Set to `true` to allow | ||
| the reboot, or `false` to have the role notify that a | ||
| reboot is required without performing it. Accepts a boolean | ||
| value or `null`. When left unset (`null`), the role fails to | ||
| ensure the reboot requirement is not overlooked. | ||
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,45 @@ | ||
| # SPDX-License-Identifier: MIT | ||
| --- | ||
| - name: Assert ssh_skip_defaults is 'auto' or a boolean | ||
| ansible.builtin.assert: | ||
| that: | ||
| - >- | ||
| (ssh_skip_defaults == 'auto') | ||
| or (ssh_skip_defaults is sameas true) | ||
| or (ssh_skip_defaults is sameas false) | ||
| fail_msg: >- | ||
| ssh_skip_defaults must be 'auto' or a boolean, | ||
| got {{ ssh_skip_defaults | type_debug }} | ||
| when: ssh_skip_defaults is defined | ||
|
|
||
| - name: Assert ssh is a dict or an empty list | ||
| ansible.builtin.assert: | ||
| that: | ||
| - >- | ||
| ssh is mapping | ||
| or (ssh is sequence and ssh is not string | ||
| and ssh is not mapping and ssh | length == 0) | ||
| fail_msg: >- | ||
| ssh must be a dict or an empty list, | ||
| got {{ ssh | type_debug }} | ||
| when: ssh is defined | ||
|
|
||
| - name: Assert ssh_config_mode is a string or integer | ||
| ansible.builtin.assert: | ||
| that: | ||
| - (ssh_config_mode | type_debug) in ['str', 'int', 'unicode'] | ||
| fail_msg: >- | ||
| ssh_config_mode must be a string or integer, | ||
| got {{ ssh_config_mode | type_debug }} | ||
| when: ssh_config_mode is not none | ||
|
|
||
| - name: Assert ssh_transactional_update_reboot_ok is null or a boolean | ||
| ansible.builtin.assert: | ||
| that: | ||
| - >- | ||
| (ssh_transactional_update_reboot_ok is none) | ||
| or (ssh_transactional_update_reboot_ok is sameas true) | ||
| or (ssh_transactional_update_reboot_ok is sameas false) | ||
| fail_msg: >- | ||
| ssh_transactional_update_reboot_ok must be null or a boolean, | ||
| got {{ ssh_transactional_update_reboot_ok | type_debug }} |
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
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
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.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Correct the documented
ssh_drop_in_namedefault.defaults/main.yml:8definesssh_drop_in_namefrom__ssh_drop_in_name, but this argument spec reportsnull. This makes the role documentation report a different default from role execution. Document the actual platform-resolved default or its condition here. Ansible requires role argument-spec documentation defaults to matchdefaults/main.yml. (docs.ansible.com)🤖 Prompt for AI Agents
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.
@DonatSzabo I think this has to be type
rawbecausedefaults/main.yml:ssh_drop_in_name: "{{ __ssh_drop_in_name }}"and
vars/main.yml:__ssh_drop_in_name: null