If you just want to use this role in a playbook, not change its code, this file isn't for you. See README.md for role variables, usage examples, and supported platforms. See GitHub Issues if you want to report a bug or request a feature without writing code yourself.
Follow these conventions when you change this role. See contribute.html for the full contributor guide.
PR title MUST follow Conventional Commits format:
- Format:
<required type><optional (scope)><optional !>: <required description> - Valid types: see https://github.com/linux-system-roles/auto-maintenance/blob/main/pr_title_lint.py#L23
- Examples:
feat: Add backup functionalityfix: Correct OSTree package installationfix!: Remove deprecated variable (breaking change)chore(formatting): Fix indentation in my_module.pyrefactor(python)!: Use new python library thispy which has breaking api changes
PR description Enhancements/Features MUST follow the template in .github/pull_request_template.md:
- Must contain "Enhancement:" or "Feature:" section describing what changed
- Must contain "Reason:" section explaining why the change was needed
- Must contain "Result:" section describing the outcome or impact
- Can contain optional "Issue Tracker Tickets (Jira or BZ if any):" section
- Must contain "Signed-off-by:" section with your name and email address - use
git commit -s - Can contain optional "Assisted-by:" section with name of the AI coding assistant and models used
Example:
Feature: Introduce the ssh_secure_logging variable
Reason: Currently, all sensitive tasks use hard-coded no_log: true, which makes debugging difficult.
Result: Users can now set ssh_secure_logging: false for debugging while maintaining secure defaults.
Issue Tracker Tickets (Jira or BZ if any): RHEL-12345
Signed-off-by: John Doe john.doe@example.com
Assisted-by: Fish 4.3 using model Swim 6.2
For bug fixes, use this template instead:
- Must contain "Cause:" section explaining the root cause of the bug
- Must contain "Consequences:" section explaining the impact of the bug and how it appears to users
- Must contain "Fix:" section explaining the fix for the bug and how it fixes the bug
- Must contain "Result:" section describing the outcome or impact of the fix
- Can contain optional "Issue Tracker Tickets (Jira or BZ if any):" section
- Must contain "Signed-off-by:" section with your name and email address - use
git commit -s - Can contain optional "Assisted-by:" section with name of the AI coding assistant and models used
Example:
Cause: The variable rolename_user_name was being checked for a `none` value but was not being checked for string length greater than 0 if a string.
Consequences: The role allowed empty user names to be configured which caused the daemon to report "User not found".
Fix: The variable rolename_user_name is now checked for string length if not `none`, and will report an error in that case if the length is 0.
Result: The role will not allow the user to provide an empty user name and will report an error if the rolename_user_name length is 0.
Signed-off-by: John Doe john.doe@example.com
Assisted-by: Fish 4.3 using model Swim 6.2
For other change types (docs, refactor, and similar), the PR or commit body does not need a fixed template, but it must still be descriptive.
If the code you add was substantially generated by AI, mark it:
-
Add an in-line comment next to the generated code, or at the top of the file after the SPDX line (if any):
# Assisted by <name of agent> using model(s) <name and version of model>[, <name and version of another model>] -
Add the same attribution in the git commit message and PR body:
Assisted-by: <name of agent> using model(s) <name and version of model>[, <name and version of another model>]
no_log patterns:
-
For sensitive data (credentials, secrets, passwords, keys):
- name: Task with sensitive data ansible.builtin.command: sensitive command no_log: "{{ ssh_secure_logging }}"
Ensure
ssh_secure_logging: trueis defined indefaults/main.yml. -
For facts modules (
package_facts,service_facts):- name: Gather package facts ansible.builtin.package_facts: no_log: "{{ ansible_verbosity < 3 }}"
This hides verbose facts output unless you run with
-vvvor higher. -
NEVER use hardcoded
no_log: true- always parametrize.
Package installation (OSTree compatibility):
- ALWAYS use the
ansible.builtin.packagemodule (NEVERyum,dnf, oraptdirectly). - ALWAYS include the
use:parameter for OSTree compatibility. - It does nothing on non-OSTree systems, so it is safe to always include it.
Typical package module usage:
- name: Ensure packages
ansible.builtin.package:
name: "{{ __ssh_packages }}"
state: present
use: "{{ (__ssh_is_ostree | d(false)) | ternary('ansible.posix.rhel_rpm_ostree', omit) }}"Explanation:
__ssh_is_ostreeistrueon OSTree/rpm-ostree systems.- The role sets this in
tasks/set_vars.ymlor similar. - DO NOT set it again.
| d(false)provides a safe default if the variable is undefined.ternary()selectsansible.posix.rhel_rpm_ostreefor OSTree,omitotherwise.omitremoves the parameter entirely on non-OSTree systems.
Using the shell: module:
- ALWAYS use the
cmdparameter to specify the script to run, never the free-form style. - ALMOST ALWAYS use
executable: /bin/bashunless you must use another shell. - ALWAYS use
set -e,set -u, andset -o pipefail(or combined asset -euo pipefail) as the first line of the script. - Ansible requires pipefail.
- ALWAYS use
changed_when:. - If you need to detect whether the script changed something, have it exit with a specific code or print a value to stdout/stderr,
register:the result, then usechanged_when:andfailed_when:conditionals.
Third-party collections:
- Avoid third-party collections (
community.general,community.crypto, etc.). - Use
ansible.builtinmodules or thecommandmodule instead.
Referencing other system roles:
- Use the FQCN:
fedora.linux_system_roles.ssh.
Idempotency:
-
Tasks must be idempotent - safe to run multiple times without unintended changes.
-
Use proper state parameters (
present/absent,started/stopped, etc.). -
command/shelltasks should usecreates/removesorchanged_whento avoid false changes. -
Example:
- name: Initialize database ansible.builtin.command: /usr/bin/initialize-db args: creates: /var/lib/db/initialized.flag
Check mode support:
- All tasks should support check mode (
--check). - Use
check_mode: falseonly when required (for example, fact gathering). - Test that the role works with
--check --diff.
Test coverage requirement:
- When you add new tasks to
tasks/main.ymlor create new task files, add matching coverage intests/. - New functionality MUST include test files (
tests/tests_*.yml) that exercise the new code paths. - Cover both success and failure or edge cases.
- If a change adds new tasks without new or updated tests, add test coverage before merging.
- Handlers with sensitive data must use
no_log: "{{ ssh_secure_logging }}".
CRITICAL: Role invocation pattern:
-
NEVER use
ansible.builtin.include_roledirectly. -
NEVER use
ansible.builtin.import_roledirectly. -
NEVER use the
roles:keyword. -
ALMOST ALWAYS use the centrally managed wrapper:
- name: Run role ansible.builtin.include_tasks: tasks/run_role_with_clear_facts.yml vars: ssh_<parameter>: <value>
-
The only exception is
tests_invalid_inputs.yml, where you can useinclude_roledirectly to test invalid inputs. -
It is not required, but it can help in some cases.
Test quality requirements:
-
Cover both success and failure scenarios.
-
Use the
assertmodule to verify expected state after role execution. -
Include cleanup tasks so tests are rerunnable.
-
Run tests in a
blockwith analwayssection that runs cleanup. -
Tag cleanup tasks with
tests::cleanupso you can skip cleanup while debugging. -
Tests must be idempotent - a second run must not fail, and must not change anything.
-
This is difficult to test.
-
Many roles track changes in each task, then use
set_factto set a variable you can assert on - for example,__kernel_settings_changedin thekernel_settingsrole tests. -
Example verification:
- name: Verify service is running ansible.builtin.assert: that: - ansible_facts.services['mssql-server.service'].state == 'running' fail_msg: "SQL Server service is not running"
Required headers, in this order:
ansible_managedheader:{{ ansible_managed | comment }}- Role fingerprint:
{{ "system_role:ssh" | comment(prefix="", postfix="") }}
- All variables MUST be prefixed with
ssh_. - All variables which have a definite default value must be declared in
defaults/main.yml. - Ansible does not load other files from
defaults/. - These are user-facing API variables.
- For every new variable, document it in
README.md(description and usage example) and inmeta/argument_specs.yml. - If either is missing, add it.
- If a variable should have no default (remain undefined unless the user sets it), do NOT add it to
defaults/main.yml. - Declare and document it only in
meta/argument_specs.yml(see below). - A placeholder or empty default defeats the purpose of leaving it undefined.
- In role code, use
is definedor| default()to guard against undefined variable access.
- Internal variables MUST be prefixed with
__ssh_. - User-facing variables belong in
defaults/main.yml, not here.
argument_specs.yml is the authoritative documentation and type or shape validation for every role variable.
Keep it in sync when you add, rename, or change a variable.
- Document every user-facing variable here: type, whether it is required, its default (if any),
choices, and a cleardescription. - Document nested suboptions (dicts or lists of dicts) the same way, recursively.
- Variables that should stay undefined by default (no sensible default, and the role or module must see them as unset unless the user sets them) must NOT get a default in
defaults/main.yml. - Declare them only in
argument_specs.yml(without adefault:key) so Ansible documents and type-checks them while they stay undefined at runtime. - Do not add a dummy or empty default in
defaults/main.ymljust to define the variable. - If a variable can be undefined, only check
when: var is defined- for example, variables declared inmeta/argument_specs.ymlbut not indefaults/main.yml. argument_specs.ymlvalidation is limited: it checks types and shapes, but it cannot express cross-field constraints (for example, "arequiresb"), cannot fully validate polymorphic orraw-typed fields that accept more than one type, and runs before the role gathers its own facts.- When you need validation beyond that, add checks in
tasks/assert_role_vars.yml(create the file if needed, and run it near the start oftasks/main.yml). - Use
tasks/assert_role_vars.ymlwhen:- A value depends on another variable (cross-field validation).
- A field accepts multiple shapes or types that
argument_specs.ymlcannot tell apart (for example, arawtype that may be a string or a dict). - See the
networkrole'sassert_connection_vars.ymlfor an example. - The check needs gathered facts or other runtime state, not only the variable value.
- Keep these checks minimal.
- Prefer
argument_specs.ymlfor everything it can express; useassert_role_vars.ymlonly for the rest.
- Document all new user-facing variables.
- Include usage examples for new functionality.