refactor(roles): validate through validate.yml, and prefix internal variables with __ROLE_ #137

Open
opened 2026-11-14 21:50:50 +00:00 by Claude · 5 comments
Owner

Spec: Role standard, resolution comment, "Validation", "Naming" and "Scenario". Scope also from Role standard gaps found in review and Role interface and semver: output facts, handler names, dropped platforms and internal roles.

Blocked by #271: the check-mode issue deletes the ufw probe tasks and their ufw_*_probe and ufw_*_check variables in tasks/sysctl.yml, tasks/orphan_rules.yml and tasks/service_rules.yml. Those variables are gone by the time this issue is built, so there is nothing to rename there.

What

  • Validation. A rule between two role variables is an assert in tasks/validate.yml. Do not express cross-input rules with spec keys: required_if, mutually_exclusive, required_together and required_one_of are used only inside a dict input's suboptions. ansible-core ignores them at entry-point level and ansible-lint refuses them there. Move systemd_hardening's inline asserts out of main.yml and dropins.yml into validate.yml.
  • Validation runs before any host change. Load validate.yml with import_tasks and tags: always in every role, and put it before every task that changes the host (only fact-computing tasks may come first).
    • fail2ban imports validate.yml before install.yml.
    • ufw's order becomes stray-guard, aggregate, validate, install, sysctl and so on. The aggregate tasks are also tagged always, because validate.yml reads ufw_aggregated_rules.
    • sshd loads validate.yml with import_tasks instead of include_tasks.
    • Add a bugfixes changelog fragment: a bad input now fails before packages or sysctl change.
  • Naming. Internal variables are renamed from <role>_ to __<role>_ in every role, along with their uses in templates, handlers and molecule. This covers register, set_fact and vars/ constants (ufw_package_name too). ansible-lint holds only the prefix; the __ is held by review. A registered variable is not part of the interface.
    • Keep the documented output facts. A fact a role documents under "Variables set by the role" is interface and keeps <role>_: system_baseline_reboot_required, user_management_all_users, user_management_managed_usernames. Every other set_fact or register is renamed to __<role>_ (for example traefik_installed_version, traefik_update_required, docker_candidates, ufw_oa_*).
    • No __ split in an internal role. _binary_update keeps _binary_update_* for all its variables. Leave it unchanged.
    • user_management is in scope.
    • Do not rename roles/system_baseline/tasks/tmux.yml. It is internal, but a consumer calls it until #186 is triaged.
  • Entry points. A supported entry point has its own argument_specs key and validates its own inputs before any change. Keep all five documented entry points working while restructuring validate.yml: system_baseline update and reboot, ufw service_rules and orphan_rules, fail2ban service_jail. Their specs and tests are #227, which follows this issue.
  • noqa. Try replacing the systemd_hardening command-instead-of-module with ansible.builtin.service_facts; keep the noqa only if that does not work. Every remaining noqa names one rule and has a reason comment.
  • Secrets. Check that every user_management task carrying user_management_become_password_hashed sets no_log: true, and fix it if not. Check that sshd's README states its secrets position.
  • Negative tests. Every validation has at least one negative test in verify.yml (or a file it includes) as block/rescue/assert, matching the expected error message, run last or failing before any change. Existing tests that only assert "it failed" are tightened.

Acceptance

Molecule and ansible-lint pass. Apart from validation now failing before any host change (with the bugfixes fragment), no role changes what it does on a host.

Spec: [Role standard](https://git.rkdr.net/Mortis/Kamino/issues/93), resolution comment, "Validation", "Naming" and "Scenario". Scope also from [Role standard gaps found in review](https://git.rkdr.net/Mortis/Kamino/issues/214) and [Role interface and semver: output facts, handler names, dropped platforms and internal roles](https://git.rkdr.net/Mortis/Kamino/issues/257). Blocked by [#271](https://git.rkdr.net/Mortis/Kamino/issues/271): the check-mode issue deletes the `ufw` probe tasks and their `ufw_*_probe` and `ufw_*_check` variables in `tasks/sysctl.yml`, `tasks/orphan_rules.yml` and `tasks/service_rules.yml`. Those variables are gone by the time this issue is built, so there is nothing to rename there. ## What - **Validation.** A rule between two role variables is an `assert` in `tasks/validate.yml`. Do not express cross-input rules with spec keys: `required_if`, `mutually_exclusive`, `required_together` and `required_one_of` are used only inside a dict input's suboptions. ansible-core ignores them at entry-point level and ansible-lint refuses them there. Move `systemd_hardening`'s inline asserts out of `main.yml` and `dropins.yml` into `validate.yml`. - **Validation runs before any host change.** Load `validate.yml` with `import_tasks` and `tags: always` in every role, and put it before every task that changes the host (only fact-computing tasks may come first). - `fail2ban` imports `validate.yml` before `install.yml`. - `ufw`'s order becomes stray-guard, aggregate, validate, install, sysctl and so on. The aggregate tasks are also tagged `always`, because `validate.yml` reads `ufw_aggregated_rules`. - `sshd` loads `validate.yml` with `import_tasks` instead of `include_tasks`. - Add a `bugfixes` changelog fragment: a bad input now fails before packages or sysctl change. - **Naming.** Internal variables are renamed from `<role>_` to `__<role>_` in every role, along with their uses in templates, handlers and molecule. This covers `register`, `set_fact` and `vars/` constants (`ufw_package_name` too). ansible-lint holds only the prefix; the `__` is held by review. A registered variable is not part of the interface. - **Keep the documented output facts.** A fact a role documents under "Variables set by the role" is interface and keeps `<role>_`: `system_baseline_reboot_required`, `user_management_all_users`, `user_management_managed_usernames`. Every other `set_fact` or `register` is renamed to `__<role>_` (for example `traefik_installed_version`, `traefik_update_required`, `docker_candidates`, `ufw_oa_*`). - **No `__` split in an internal role.** `_binary_update` keeps `_binary_update_*` for all its variables. Leave it unchanged. - `user_management` is in scope. - Do not rename `roles/system_baseline/tasks/tmux.yml`. It is internal, but a consumer calls it until [#186](https://git.rkdr.net/Mortis/Kamino/issues/186) is triaged. - **Entry points.** A supported entry point has its own argument_specs key and validates its own inputs before any change. Keep all five documented entry points working while restructuring `validate.yml`: `system_baseline` `update` and `reboot`, `ufw` `service_rules` and `orphan_rules`, `fail2ban` `service_jail`. Their specs and tests are [#227](https://git.rkdr.net/Mortis/Kamino/issues/227), which follows this issue. - **`noqa`.** Try replacing the `systemd_hardening` `command-instead-of-module` with `ansible.builtin.service_facts`; keep the `noqa` only if that does not work. Every remaining `noqa` names one rule and has a reason comment. - **Secrets.** Check that every `user_management` task carrying `user_management_become_password_hashed` sets `no_log: true`, and fix it if not. Check that `sshd`'s README states its secrets position. - **Negative tests.** Every validation has at least one negative test in `verify.yml` (or a file it includes) as block/rescue/assert, matching the expected error message, run last or failing before any change. Existing tests that only assert "it failed" are tightened. ## Acceptance Molecule and ansible-lint pass. Apart from validation now failing before any host change (with the `bugfixes` fragment), no role changes what it does on a host.
Claude added the
Status
Ready for Agent
label 2026-11-14 21:50:50 +00:00
Claude changed title from refactor(roles): validate through spec keys and validate.yml, and prefix internal variables with __&lt;role&gt;_ to refactor(roles): validate through spec keys and validate.yml, and prefix internal variables with __ROLE_ 2026-11-14 21:50:55 +00:00
Claude added this to the Continuous delivery milestone 2026-11-15 22:21:20 +00:00
Author
Owner

Correction from What a role's platform declaration means, and supported entry points:

  • A supported entry point has its own argument_specs key and validates its own inputs before any change. While restructuring validate.yml, keep the documented entry points (system_baseline update and reboot, ufw service_rules) working. Giving them specs and tests is #227, which follows this issue.
  • Do not rename roles/system_baseline/tasks/tmux.yml. It is internal, but a consumer calls it until #186 is triaged.
Correction from [What a role's platform declaration means, and supported entry points](https://git.rkdr.net/Mortis/Kamino/issues/207): - A supported entry point has its own argument_specs key and validates its own inputs before any change. While restructuring `validate.yml`, keep the documented entry points (`system_baseline` `update` and `reboot`, `ufw` `service_rules`) working. Giving them specs and tests is [#227](https://git.rkdr.net/Mortis/Kamino/issues/227), which follows this issue. - Do not rename `roles/system_baseline/tasks/tmux.yml`. It is internal, but a consumer calls it until [#186](https://git.rkdr.net/Mortis/Kamino/issues/186) is triaged.
Author
Owner

Scope added by Role standard gaps found in review (resolution comment, rules 1, 2, 3 and 7):

  • __<role>_ covers register, set_fact and vars/ constants (ufw_package_name too). ansible-lint holds only the prefix; the __ is held by review.
  • Move validation before any host change, not only tag it: fail2ban imports validate.yml before install.yml; ufw's order becomes stray-guard → aggregate → validate → install → sysctl → … with the aggregate tasks also tagged always (validate reads ufw_aggregated_rules); sshd loads validate.yml with import_tasks instead of include_tasks. Load it with import_tasks and tags: always in every role. Add a bugfixes fragment: a bad input now fails before packages or sysctl change.
  • noqa: try replacing the systemd_hardening command-instead-of-module with ansible.builtin.service_facts; keep the noqa only if that does not work. Every remaining noqa names one rule and has a reason comment.
  • Secrets: check that every user_management task carrying user_management_become_password_hashed sets no_log: true, and fix it if not; check sshd's README states its secrets position.
Scope added by [Role standard gaps found in review](https://git.rkdr.net/Mortis/Kamino/issues/214) (resolution comment, rules 1, 2, 3 and 7): - **`__<role>_`** covers `register`, `set_fact` and `vars/` constants (`ufw_package_name` too). ansible-lint holds only the prefix; the `__` is held by review. - **Move validation before any host change**, not only tag it: fail2ban imports `validate.yml` before `install.yml`; ufw's order becomes stray-guard → aggregate → validate → install → sysctl → … with the aggregate tasks also tagged `always` (validate reads `ufw_aggregated_rules`); sshd loads `validate.yml` with `import_tasks` instead of `include_tasks`. Load it with `import_tasks` and `tags: always` in every role. Add a `bugfixes` fragment: a bad input now fails before packages or sysctl change. - **`noqa`**: try replacing the `systemd_hardening` `command-instead-of-module` with `ansible.builtin.service_facts`; keep the `noqa` only if that does not work. Every remaining `noqa` names one rule and has a reason comment. - **Secrets**: check that every `user_management` task carrying `user_management_become_password_hashed` sets `no_log: true`, and fix it if not; check `sshd`'s README states its secrets position.
Author
Owner

Review of the map (2026-11-17).

  • Validation. The bullet says "Express cross-input rules with the spec's keys where possible". It should say: a rule between two role variables is an assert in tasks/validate.yml; required_if, mutually_exclusive, required_together and required_one_of are used only inside a dict input's suboptions. Ansible ignores them at entry-point level and ansible-lint refuses them there (reproduced on ansible-core 2.22.0 and ansible-lint 26.10.1; see the note on Role standard).
  • Entry points. The comment of 2026-11-16 lists the documented entry points as system_baseline update and reboot and ufw service_rules. The full list is: system_baseline update, reboot; ufw service_rules, orphan_rules; fail2ban service_jail. Keep all five working.
  • Output facts. The rename covers every set_fact, but three facts are documented for consumers: system_baseline_reboot_required, user_management_all_users, user_management_managed_usernames. Renaming them breaks callers, while the acceptance says "No role changes what it does on a host." Do not rename a fact a role README documents until Role interface and semver: output facts, handler names, dropped platforms and internal roles is answered.
  • roles/ holds eight roles now; user_management is in scope.

Changed: this issue is now blocked by that ticket.

Proposed, not done: title "refactor(roles): validate through validate.yml, and prefix internal variables with _ROLE".

Review of the map (2026-11-17). - **Validation.** The bullet says "Express cross-input rules with the spec's keys where possible". It should say: a rule between two role variables is an `assert` in `tasks/validate.yml`; `required_if`, `mutually_exclusive`, `required_together` and `required_one_of` are used only inside a dict input's suboptions. Ansible ignores them at entry-point level and ansible-lint refuses them there (reproduced on ansible-core 2.22.0 and ansible-lint 26.10.1; see the note on [Role standard](https://git.rkdr.net/Mortis/Kamino/issues/93)). - **Entry points.** The comment of 2026-11-16 lists the documented entry points as `system_baseline` `update` and `reboot` and `ufw` `service_rules`. The full list is: `system_baseline` `update`, `reboot`; `ufw` `service_rules`, `orphan_rules`; `fail2ban` `service_jail`. Keep all five working. - **Output facts.** The rename covers every `set_fact`, but three facts are documented for consumers: `system_baseline_reboot_required`, `user_management_all_users`, `user_management_managed_usernames`. Renaming them breaks callers, while the acceptance says "No role changes what it does on a host." Do not rename a fact a role README documents until [Role interface and semver: output facts, handler names, dropped platforms and internal roles](https://git.rkdr.net/Mortis/Kamino/issues/257) is answered. - `roles/` holds eight roles now; `user_management` is in scope. Changed: this issue is now blocked by that ticket. Proposed, not done: title "refactor(roles): validate through validate.yml, and prefix internal variables with __ROLE_".
Author
Owner

Scope change from Role interface and semver: output facts, handler names, dropped platforms and internal roles (2026-11-20)

  • Keep the three documented output facts as they are: system_baseline_reboot_required, user_management_all_users, user_management_managed_usernames. A fact a role documents under "Variables set by the role" is interface and keeps <role>_. Every other set_fact or register is renamed to __<role>_ (for example traefik_installed_version, traefik_update_required, docker_candidates, ufw_oa_*).
  • No __ split in an internal role: _binary_update keeps _binary_update_* for all its variables. Leave it unchanged.
## Scope change from [Role interface and semver: output facts, handler names, dropped platforms and internal roles](https://git.rkdr.net/Mortis/Kamino/issues/257) (2026-11-20) - **Keep the three documented output facts as they are**: `system_baseline_reboot_required`, `user_management_all_users`, `user_management_managed_usernames`. A fact a role documents under "Variables set by the role" is interface and keeps `<role>_`. Every other `set_fact` or `register` is renamed to `__<role>_` (for example `traefik_installed_version`, `traefik_update_required`, `docker_candidates`, `ufw_oa_*`). - **No `__` split in an internal role**: `_binary_update` keeps `_binary_update_*` for all its variables. Leave it unchanged.
Claude changed title from refactor(roles): validate through spec keys and validate.yml, and prefix internal variables with __ROLE_ to refactor(roles): validate through validate.yml, and prefix internal variables with __ROLE_ 2026-11-20 22:12:10 +00:00
Claude added a new dependency 2026-11-20 22:12:10 +00:00
Author
Owner

Final validation round, second pass (2026-11-20): body edited.

  • Validation: cross-input rules are asserts in validate.yml; spec keys only inside dict suboptions.
  • Validation moves before any host change (import_tasks, tags: always), with the bugfixes fragment; acceptance adjusted to match.
  • Naming: documented output facts keep <role>_; internal roles have no __ split.
  • Entry points: all five listed; tmux.yml not renamed; noqa and secrets checks folded in.
  • Title now the one proposed on 2026-11-17 (unchanged in substance).
  • Added blocked by #271, which deletes the ufw probe and check variables this issue would otherwise rename.

The comments above stay as history.

Final validation round, second pass (2026-11-20): body edited. - Validation: cross-input rules are asserts in `validate.yml`; spec keys only inside dict suboptions. - Validation moves before any host change (`import_tasks`, `tags: always`), with the `bugfixes` fragment; acceptance adjusted to match. - Naming: documented output facts keep `<role>_`; internal roles have no `__` split. - Entry points: all five listed; `tmux.yml` not renamed; `noqa` and secrets checks folded in. - Title now the one proposed on 2026-11-17 (unchanged in substance). - Added blocked by #271, which deletes the `ufw` probe and check variables this issue would otherwise rename. The comments above stay as history.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Reference: Mortis/Kamino#137