Role standard #93

Closed
opened 2026-11-11 22:02:57 +00:00 by Claude · 2 comments
Owner

Part of #87

Question

What must every role in this Collection have and do, and which of those requirements are checked automatically?

Cover: layout, README shape, argument_specs, variable naming, declared platforms versus tested platforms, check-mode behaviour, molecule scenario shape (converge, negative tests, verify, idempotence), which Ubuntu releases a role must pass on, and the max_tasks number for ansible-lint's complexity rule.

Context

  • Start from public practice (Ansible collection requirements; per-role README with a variables table and example play; argument_specs as the documented interface), then from what the maintainer's repositories already do consistently.
  • The four roles here share a layout but differ: declared platforms do not match what is tested, only one README has a Tests section, and no role scenario runs on 26.04 although the docs say roles are tested on both releases.
  • In the maintainer's environment repository, check-mode breakage was the most frequent class of fix; a --check run in molecule is a candidate requirement.
  • There is no written role standard today beyond the variable-prefix rule.
  • Guiding principles for agents and humans decided to enable ansible-lint's complexity rule (default max_tasks 100) and left the number here. First confirm with ansible-lint -L that the rule is active under the production profile; that was not verified. The five code-style rules and the form of a rule (rule, reason, how it is held) decided there apply to roles too.
Part of #87 ## Question What must every role in this Collection have and do, and which of those requirements are checked automatically? Cover: layout, README shape, `argument_specs`, variable naming, declared platforms versus tested platforms, check-mode behaviour, molecule scenario shape (converge, negative tests, verify, idempotence), which Ubuntu releases a role must pass on, and the `max_tasks` number for ansible-lint's `complexity` rule. ## Context - Start from public practice (Ansible collection requirements; per-role README with a variables table and example play; `argument_specs` as the documented interface), then from what the maintainer's repositories already do consistently. - The four roles here share a layout but differ: declared platforms do not match what is tested, only one README has a Tests section, and no role scenario runs on 26.04 although the docs say roles are tested on both releases. - In the maintainer's environment repository, check-mode breakage was the most frequent class of fix; a `--check` run in molecule is a candidate requirement. - There is no written role standard today beyond the variable-prefix rule. - [Guiding principles for agents and humans](https://git.rkdr.net/Mortis/Kamino/issues/91) decided to enable ansible-lint's `complexity` rule (default `max_tasks` 100) and left the number here. First confirm with `ansible-lint -L` that the rule is active under the production profile; that was not verified. The five code-style rules and the form of a rule (rule, reason, how it is held) decided there apply to roles too.
Claude added the
Wayfinder
Grilling
label 2026-11-11 22:02:57 +00:00
Defame1297 was assigned by Claude 2026-11-14 16:40:39 +00:00
Author
Owner

Resolution: rules for roles

Decided in a grilling session, every point checked against primary sources (Ansible docs and ansible-core source, molecule source, ansible-lint 26.10.1 source, galaxy-importer, Red Hat CoP automation good practices, linux-system-roles). Each rule: the rule, its reason, how it is held.

Layout. Every role has tasks/main.yml, defaults/main.yml, meta/main.yml, meta/argument_specs.yml, README.md and molecule/default/; vars/ holds only constants a consumer must not override. Reason: one predictable shape; vars/ outranks inventory, so a default there cannot be overridden (CoP). Held: the scenario by control (select_molecule_scenarios.py fails a changed role without one); the rest by review.

Interface (argument_specs). Every optional input has a value in defaults/main.yml and an entry in the spec with type, description and the same default:; choices for closed value sets; required: true inputs have no default (CoP: no meaningless defaults). Suboption defaults are documentation only, so the role applies them itself. Reason: the spec is the documented interface; a spec default: never sets the variable, but without it ansible-doc -t role shows null. Held: control, a CI check that spec defaults equal defaults/main.yml (ansible-docsmith validate if it proves reliable, else a short pinned script: the one accepted exception to "no custom checker").

Validation. Use the spec's cross-input keys (required_if, mutually_exclusive, required_together, required_one_of) first; an assert in tasks/validate.yml only for what the spec cannot express; main.yml includes it first with tags: always. Reason: fail before any change, and a --tags run cannot skip it. Held: review.

Naming. Inputs are prefixed <role>_; internal variables (vars/, set_fact, register:) __<role>_; noqa only in test fixtures, with a reason on the line. Reason: no collisions across roles; the interface is visible by name (CoP, linux-system-roles). Held: control, ansible-lint var-naming[no-role-prefix] (production profile).

README. Fixed, hand-written headings: Supported platforms; Requirements and run order; Role variables (table); Entry points (when several); Variables set by the role (when any); Tags; Example play; Tests; Notes, including an "Idempotent: yes/no" line. No licence or author heading: those are Collection-level. Reason: a consumer finds the same thing in the same place; generation adds a tool and cannot write the prose that explains a deliberate choice. Held: review.

Platforms. meta/main.yml platforms, the README and the molecule platforms all list exactly Ubuntu noble (24.04) and resolute (26.04), never all; every role passes on both. Reason: the hosts run 24.04 and 26.04 is the target; a declared platform nobody tests is a false claim. galaxy-importer ignores platforms for collection roles, so the README and molecule are the real declaration. Held: molecule (control) for passing; review for the declarations matching.

Check mode. Every scenario's test_sequence runs check before converge (fresh host) and after it (configured host); molecule asserts only that it does not fail. Allowed guards: check_mode: false on read-only probes, when: not ansible_check_mode. A role that cannot support check mode says why in README Notes and drops the step. Reason: check-mode breakage was the most frequent fix class in the environment it came from; CoP says roles must not fail in check mode. Held: control (molecule). Unverified: that molecule accepts the same step twice; if not, keep the before-converge run.

Scenario. One default scenario with converge, idempotence and verify. Verify asserts the runtime effect (the service loaded the config, systemd sees the drop-in), not only rendered files. Every validation has at least one negative test in verify.yml (or files it includes) as block/rescue/assert matching the expected error message, run last or failing before any change. Reason: a rendered file proves nothing about the host; a bare "it failed" passes for the wrong error. Held: idempotence by control; the rest by review.

Complexity. enable_list: [complexity] with the default max_tasks (100), gated with warn_list: []. Reason: max_tasks cannot be set today: ansible-lint's config schema rejects the key (reproduced on 26.10.1; nearest upstream issue ansible/ansible-lint#4824), and experimental findings only warn unless the warn list is empty. Lower to 40 once that is fixed. This defers the number left open by Guiding principles for agents and humans. Held: control (ansible-lint, Lint job).

Existing roles are brought into line now; none of these changes what a role does on a host. No ADR: each rule is cheap to reverse and carries its reason.

Where the rules are written down waits on Contributor doc set (recorded as implementation owed on the map).

## Resolution: rules for roles Decided in a grilling session, every point checked against primary sources (Ansible docs and ansible-core source, molecule source, ansible-lint 26.10.1 source, galaxy-importer, Red Hat CoP automation good practices, linux-system-roles). Each rule: the rule, its reason, how it is held. **Layout.** Every role has `tasks/main.yml`, `defaults/main.yml`, `meta/main.yml`, `meta/argument_specs.yml`, `README.md` and `molecule/default/`; `vars/` holds only constants a consumer must not override. *Reason:* one predictable shape; `vars/` outranks inventory, so a default there cannot be overridden (CoP). *Held:* the scenario by control (`select_molecule_scenarios.py` fails a changed role without one); the rest by review. **Interface (argument_specs).** Every optional input has a value in `defaults/main.yml` and an entry in the spec with `type`, `description` and the same `default:`; `choices` for closed value sets; `required: true` inputs have no default (CoP: no meaningless defaults). Suboption defaults are documentation only, so the role applies them itself. *Reason:* the spec is the documented interface; a spec `default:` never sets the variable, but without it `ansible-doc -t role` shows `null`. *Held:* control, a CI check that spec defaults equal `defaults/main.yml` (`ansible-docsmith validate` if it proves reliable, else a short pinned script: the one accepted exception to "no custom checker"). **Validation.** Use the spec's cross-input keys (`required_if`, `mutually_exclusive`, `required_together`, `required_one_of`) first; an `assert` in `tasks/validate.yml` only for what the spec cannot express; `main.yml` includes it first with `tags: always`. *Reason:* fail before any change, and a `--tags` run cannot skip it. *Held:* review. **Naming.** Inputs are prefixed `<role>_`; internal variables (`vars/`, `set_fact`, `register:`) `__<role>_`; `noqa` only in test fixtures, with a reason on the line. *Reason:* no collisions across roles; the interface is visible by name (CoP, linux-system-roles). *Held:* control, ansible-lint `var-naming[no-role-prefix]` (production profile). **README.** Fixed, hand-written headings: Supported platforms; Requirements and run order; Role variables (table); Entry points (when several); Variables set by the role (when any); Tags; Example play; Tests; Notes, including an "Idempotent: yes/no" line. No licence or author heading: those are Collection-level. *Reason:* a consumer finds the same thing in the same place; generation adds a tool and cannot write the prose that explains a deliberate choice. *Held:* review. **Platforms.** `meta/main.yml` `platforms`, the README and the molecule platforms all list exactly Ubuntu `noble` (24.04) and `resolute` (26.04), never `all`; every role passes on both. *Reason:* the hosts run 24.04 and 26.04 is the target; a declared platform nobody tests is a false claim. galaxy-importer ignores `platforms` for collection roles, so the README and molecule are the real declaration. *Held:* molecule (control) for passing; review for the declarations matching. **Check mode.** Every scenario's `test_sequence` runs `check` before converge (fresh host) and after it (configured host); molecule asserts only that it does not fail. Allowed guards: `check_mode: false` on read-only probes, `when: not ansible_check_mode`. A role that cannot support check mode says why in README Notes and drops the step. *Reason:* check-mode breakage was the most frequent fix class in the environment it came from; CoP says roles must not fail in check mode. *Held:* control (molecule). Unverified: that molecule accepts the same step twice; if not, keep the before-converge run. **Scenario.** One `default` scenario with converge, idempotence and verify. Verify asserts the runtime effect (the service loaded the config, systemd sees the drop-in), not only rendered files. Every validation has at least one negative test in `verify.yml` (or files it includes) as block/rescue/assert matching the expected error message, run last or failing before any change. *Reason:* a rendered file proves nothing about the host; a bare "it failed" passes for the wrong error. *Held:* idempotence by control; the rest by review. **Complexity.** `enable_list: [complexity]` with the default `max_tasks` (100), gated with `warn_list: []`. *Reason:* `max_tasks` cannot be set today: ansible-lint's config schema rejects the key (reproduced on 26.10.1; nearest upstream issue ansible/ansible-lint#4824), and experimental findings only warn unless the warn list is empty. Lower to 40 once that is fixed. This defers the number left open by [Guiding principles for agents and humans](https://git.rkdr.net/Mortis/Kamino/issues/91). *Held:* control (ansible-lint, Lint job). **Existing roles** are brought into line now; none of these changes what a role does on a host. **No ADR:** each rule is cheap to reverse and carries its reason. Where the rules are written down waits on [Contributor doc set](https://git.rkdr.net/Mortis/Kamino/issues/103) (recorded as implementation owed on the map).
Author
Owner

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

Partly superseded by What a role's platform declaration means, and supported entry points: platforms follow the target hosts (Ubuntu targets declare noble and resolute, Proxmox targets declare Debian trixie), and the same decision defines what a supported entry point is.

Partly superseded by Role standard gaps found in review: validate.yml is loaded with import_tasks and tags: always before any task that changes the host. A noqa is allowed when it names one rule and carries a reason. ansible-lint holds the role prefix; review holds the __.

Correction to the Validation rule. It says to use the spec's cross-input keys "first". On ansible-core 2.22.0 required_if, mutually_exclusive, required_together and required_one_of are ignored when they sit next to options under an entry point (only options reaches the validator, ansible/playbook/role/__init__.py:392), and ansible-lint 26.10.1 refuses them there with schema[role-arg-spec]. Reproduced with a scratch role. They work only inside a dict input, for its suboptions. The rule therefore reads:

  • Rule: the spec holds type, choices and required per input; a rule between two role variables is an assert in tasks/validate.yml; the cross-input keys are used only inside a dict input's suboptions.
  • Reason: Ansible does not apply them at entry-point level.
  • Held: ansible-lint for the misuse, review for the rest.

No new decision is needed: the rule's own second half ("an assert ... only for what the spec cannot express") already leads here. Not certain whether a newer ansible-core adds entry-point support.

Open after this review: whether output facts, handler names and internal roles are part of a role's interface (Role interface and semver: output facts, handler names, dropped platforms and internal roles).

Review of the map (2026-11-17). Partly superseded by [What a role's platform declaration means, and supported entry points](https://git.rkdr.net/Mortis/Kamino/issues/207): platforms follow the target hosts (Ubuntu targets declare `noble` and `resolute`, Proxmox targets declare Debian `trixie`), and the same decision defines what a supported entry point is. Partly superseded by [Role standard gaps found in review](https://git.rkdr.net/Mortis/Kamino/issues/214): `validate.yml` is loaded with `import_tasks` and `tags: always` before any task that changes the host. A `noqa` is allowed when it names one rule and carries a reason. ansible-lint holds the role prefix; review holds the `__`. **Correction to the Validation rule.** It says to use the spec's cross-input keys "first". On ansible-core 2.22.0 `required_if`, `mutually_exclusive`, `required_together` and `required_one_of` are ignored when they sit next to `options` under an entry point (only `options` reaches the validator, `ansible/playbook/role/__init__.py:392`), and ansible-lint 26.10.1 refuses them there with `schema[role-arg-spec]`. Reproduced with a scratch role. They work only inside a dict input, for its suboptions. The rule therefore reads: - Rule: the spec holds `type`, `choices` and `required` per input; a rule between two role variables is an `assert` in `tasks/validate.yml`; the cross-input keys are used only inside a dict input's suboptions. - Reason: Ansible does not apply them at entry-point level. - Held: ansible-lint for the misuse, review for the rest. No new decision is needed: the rule's own second half ("an `assert` ... only for what the spec cannot express") already leads here. Not certain whether a newer ansible-core adds entry-point support. Open after this review: whether output facts, handler names and internal roles are part of a role's interface ([Role interface and semver: output facts, handler names, dropped platforms and internal roles](https://git.rkdr.net/Mortis/Kamino/issues/257)).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mortis/Kamino#93