test_roles_call_each_other_by_full_name_only in tests/scripts/test_select_molecule_scenarios.py already fails when a role's meta/main.yml declares dependencies, and Lint runs it through the script-tests hook. That test is the Lint check the rule waited for, so the rule now names it as its control, and the workflow rules and the selector's docstring no longer describe a meta dependency as allowed. Refs: #246 Assisted-by: Claude Code
132 lines
9.4 KiB
Markdown
132 lines
9.4 KiB
Markdown
# Role rules
|
|
|
|
Every rule for a role in this Collection, in full. Each gives its reason (*Why*) and how it is
|
|
held (*Held*): a control names its hook or check; review means a person other than the author
|
|
sees the change before it merges; aspirational means nothing checks it. "Until X (#N) lands"
|
|
names a check that does not exist yet and its backlog issue.
|
|
|
|
## Shape
|
|
|
|
- **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.
|
|
*Why:* one predictable shape, and `vars/` outranks inventory. *Held:* the scenario by
|
|
`scripts/select_molecule_scenarios.py` (fails a changed role without one), the rest by review.
|
|
- **README headings (public roles).** 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, with an "Idempotent: yes/no" line. No licence or author heading.
|
|
*Why:* a consumer finds the same thing in the same place. *Held:* review.
|
|
- **Complexity.** A task file stays within ansible-lint's `complexity` limit, `max_tasks` 100
|
|
(40 once ansible-lint accepts the key). *Why:* a long task file is hard to review. *Held:*
|
|
control, ansible-lint `complexity` in the Lint job.
|
|
- **Roadmap.** The pull request that adds a role removes it from the README "Roadmap" list, and
|
|
the section goes when the list is empty. *Why:* the list is useful only if true. *Held:* review.
|
|
|
|
## Interface
|
|
|
|
- **Role interface.** Inputs, supported entry points, documented output facts and documented
|
|
tags (README `## Tags`). Renaming or removing one is a `breaking_changes` fragment (a major
|
|
release), for an input with no compatibility alias; adding one is `minor_changes`. *Why:* this
|
|
is what a consumer may depend on, and with latest-only support an alias costs more than it
|
|
gives. *Held:* review; the fragment check (#183) will require a fragment, not pick its section.
|
|
- **argument_specs.** Every optional input has a value in `defaults/main.yml` and a spec entry
|
|
with `type`, `description` and the same `default:`; `choices` for closed sets; a `required:
|
|
true` input has no default. *Why:* a spec `default:` never sets the variable, but without it
|
|
`ansible-doc -t role` shows `null`. *Held:* review until the spec-defaults drift check (#135).
|
|
- **Suboption defaults.** The role applies them itself; spec suboption defaults are
|
|
documentation. *Why:* Ansible does not apply them. *Held:* review; the drift check (#135) will
|
|
hold those it can see.
|
|
- **Supported entry points.** Each has its own spec key, runs its validation before any change,
|
|
has an "Entry points" README entry and a Molecule scenario; every other `tasks/*.yml` is
|
|
internal and may be renamed. *Why:* a consumer must tell what it may call. *Held:* review until
|
|
the drift check compares spec keys, README entries and task files (#227).
|
|
- **Output facts.** A fact documented under "Variables set by the role" keeps `<role>_`;
|
|
everything else a role sets or registers is `__<role>_`. *Why:* the name says what is
|
|
interface. *Held:* review.
|
|
- **Handlers are internal.** A caller never notifies a role's handler; a README names one only
|
|
to explain behaviour; renaming one needs no fragment. *Why:* handler names are global in a
|
|
play, so a caller bound to one breaks on a rename. *Held:* review.
|
|
|
|
## Variables and validation
|
|
|
|
- **Internal variables.** `vars/` constants, `register:` and `set_fact` results are `__<role>_`.
|
|
*Why:* the Red Hat Automation Good Practices convention, and it tells an input from an internal
|
|
name. *Held:* ansible-lint `var-naming[no-role-prefix]` for the prefix, review for the `__`.
|
|
The check misreads a leading `_`, so an internal role's files are listed in
|
|
`.ansible-lint-ignore` and its prefix is held by review.
|
|
- **Validation.** The spec holds `type`, `choices` and `required`; a rule between role variables
|
|
is an `assert` in `tasks/validate.yml`; cross-input spec keys (`required_if`,
|
|
`mutually_exclusive` and the like) appear only inside a dict input's suboptions. *Why:* Ansible
|
|
does not apply them at entry-point level. *Held:* ansible-lint `schema[role-arg-spec]` for
|
|
entry-level misuse, review for the rest.
|
|
- **Validation order.** `validate.yml` runs before any task that changes the host, loaded with
|
|
`import_tasks` and `tags: always`; only fact-computing tasks run before it, tagged `always`
|
|
too. *Why:* a bad input fails before any change, and `always` on `include_tasks` does not reach
|
|
the included tasks. *Held:* review.
|
|
- **`noqa`.** Prefer fixing a finding; a `noqa` that remains names one rule and has a reason
|
|
comment. *Why:* an unexplained exception cannot be reviewed. *Held:* review.
|
|
- **Secrets.** Never in plaintext in the repository, a role's defaults, task output or a file on
|
|
the controller; `no_log: true` on every task that carries one; a secret is a required input
|
|
with no default; a role generates one only straight into a secret store the consumer names.
|
|
Keys a host generates for itself and keeps (SSH host keys) are not covered. The README line
|
|
"`no_log` is not used: the role handles no secrets" stays only where true. *Why:* nothing leaks
|
|
today and a role writing to a secret store stays possible. *Held:* review.
|
|
|
|
## Platforms
|
|
|
|
- **Declared means tested.** A platform in `meta/main.yml` is one the role passes Molecule on in
|
|
CI; one used but untested goes only in a README "Untested platforms" line. Accepted until the
|
|
Debian image (#226) lands: `trixie` declared untested, and Debian `all` in network_interfaces.
|
|
*Why:* no tool reads the declaration, so it is worth something only if true. *Held:* review.
|
|
- **Platforms follow the target hosts.** Ubuntu-targeting roles declare exactly `noble` and
|
|
`resolute`; Proxmox-targeting roles declare Debian `trixie`; each is tested on its own OS.
|
|
*Why:* testing on hosts a role never runs on proves nothing. *Held:* review.
|
|
- **All three releases.** A role aims to target both Ubuntu and Proxmox hosts, and so to declare
|
|
`noble`, `resolute` and `trixie`; one that covers fewer says why in one README line. *Why:* a
|
|
wider role serves more hosts. *Held:* aspirational.
|
|
- **Dropping a platform.** Removing or narrowing a declared platform is `breaking_changes`,
|
|
tested or not. *Why:* a consumer on it loses support. *Held:* review until the fragment check
|
|
fails a dropped platform without one (#183).
|
|
|
|
## Tests
|
|
|
|
- **Verify** asserts the effect on the host (the service loaded the config), not only rendered
|
|
files. *Why:* a rendered file proves nothing about a running service. *Held:* review.
|
|
- **Negative tests.** Every validation has one in `verify.yml` (or a file it includes):
|
|
block/rescue/assert matching the expected error message, run last or failing before any
|
|
change. *Why:* a bare "it failed" passes for the wrong error. *Held:* review.
|
|
- **Check mode.** Every scenario runs `check` before and after converge. Guards:
|
|
`check_mode: false` on read-only probes, and `when: not ansible_check_mode`, alone or as
|
|
`not ansible_check_mode or <condition>` where the condition shows the task can run (such as a
|
|
registered result that is not changed). README: `--check` is the supported preview and a
|
|
play-level `check_mode: true` is not supported; a role whose `--check` needs its package
|
|
installed says so in Notes and keeps the step; a role that cannot support check mode at all
|
|
says why in Notes and drops the step, which also needs an exception in the test named below.
|
|
*Why:* check-mode breakage is a frequent fix, and one guard pattern is reviewable. *Held:*
|
|
Molecule for the run passing, `tests/scripts/test_run_molecule_scenarios.py` for the steps
|
|
being there; review for the guards.
|
|
|
|
## Roles calling roles
|
|
|
|
- **Dependencies.** A role uses another role of this Collection only through
|
|
`ansible.builtin.include_role` or `import_role` by FQCN, never a role outside the Collection,
|
|
and lists it in its README; `meta/main.yml` `dependencies` stays `[]`. It calls a public role
|
|
only on a supported entry point, an internal role on any entry point in its argument_specs.
|
|
*Why:* a task-level include keeps the order readable, where `meta` dependencies run hidden and
|
|
deduplicated. *Held:* the selector runs a dependent role's scenarios when a role it uses
|
|
changes; control: `test_roles_call_each_other_by_full_name_only` in
|
|
`tests/scripts/test_select_molecule_scenarios.py`, run by the Lint check, fails a non-empty
|
|
`dependencies`.
|
|
- **Internal roles.** A leading `_`; only roles of this Collection call it, by FQCN; it refuses
|
|
to run without a parent role (an `assert` on `ansible_parent_role_names`, as in
|
|
`_binary_update`); it has argument_specs and Molecule scenarios and follows the platform rules.
|
|
Its README opens with the internal-role statement and otherwise keeps its own headings. Its
|
|
variables keep `_<role>_`, with no `__` split. It is outside semver: a change confined to it
|
|
takes a `trivial` fragment, and the calling role writes the fragment for any effect a consumer
|
|
can see. *Why:* shared machinery without a versioning promise. *Held:* the assert at run time;
|
|
review that each new internal role has it.
|
|
- **`role-name` for internal roles.** An internal role is exempted from ansible-lint `role-name`
|
|
by its own line in `.ansible-lint-ignore`. *Why:* a misnamed public role must still fail.
|
|
*Held:* control, ansible-lint `role-name` in the Lint job; review that each new internal role
|
|
has its line.
|