feat(user_management): add the user_management role #231

Merged
Defame1297 merged 5 commits from feat/user-management-role into main 2026-11-16 17:43:34 +00:00
Owner

Adds the user_management role, the last role of wave 1. It is copied from the environment repository's local role, plus one behaviour fix (the handback, below) found in review.

What changed against the source

  • meta/main.yml namespace is mortis.
  • Comments and the README carry no environment references (issue numbers, playbooks, inventory paths and groups, provisioning role names). The sshd role is named without its FQCN (role-independence test). The technical explanations stay.
  • The molecule scenario calls the role as mortis.kamino.user_management, follows the Kamino conventions (kamino-molecule header, scenario.test_sequence) and drops provisioner.env. prepare.yml and verify.yml are unchanged, so test coverage is the same.
  • Fix, tasks/bootstrap.yml and tasks/handback.yml: the handback switched the connection back to ansible_user, while the role creates user_management_ansible_user.name. When the two differed, the root fallback created a user nobody connects as, and the handback then failed after the changes made as root (or later plays connected as the wrong user). The fallback now asserts, before switching to root, that the primary user's name equals ansible_user (set as a variable). The handback switches to the user the role created. There is no change where the names are equal, which is the default (name: "{{ ansible_user }}") and the only case in the environment repository (no host overrides user_management_ansible_user).
  • Docs, from review:
    • gather_facts: false is required, otherwise a fresh guest is unreachable before the fallback runs. This is now in the README requirements and example and in the argument spec.
    • user_management_authoritative skips a user whose merged key list is empty, so emptying the list does not remove that user's keys.
    • user_management_become_password_hashed is required unless user_management_ansible_user is overridden.
    • The defaults/main.yml comment no longer says usermod -L.
    • Known limits are listed: molecule does not exercise the fallback or the handback (the docker connection always connects), a tag-only run on a fresh host fails at the handback, and the primary user can be set absent.
  • galaxy.yml: only the dependency comment names user_management as an ansible.posix user (authorized_key). ansible.posix >=2.2.0 is already declared. The version is left for the release commit.
  • Changelog fragment user-management-role.yml. The README Roadmap no longer lists wave 1. The CLAUDE.md role list is updated.

Verified

  • All pre-commit hooks on every commit (ansible-lint production profile with FQCN resolution, yamllint, REUSE, changelog lint, gitleaks) and the pre-push ansible-test sanity.
  • tests/scripts/test_select_molecule_scenarios.py (20 tests, including test_no_role_refers_to_another_role).
  • diff -r against the source: tasks, defaults, argument_specs types and defaults, prepare.yml and verify.yml match, apart from the fix and comments above.
  • An independent subagent review (read-only), which found no blockers. Its should-fix items are applied above. It ran converge.yml --syntax-check and confirmed that the workflow's collection path resolves the FQCN.

Not verified

  • The molecule scenario. It runs here in CI on the kamino-molecule runner. This is also the first run without the source's ANSIBLE_COLLECTIONS_PATH, so it confirms that ansible.posix resolves from the workflow's path.
  • The root fallback and the handback, including the new assert. The scenario cannot exercise them (docker connection). They are reasoned through only. The environment's last live exercise of the fallback predates the assert.
  • Converge on 22.04 or a Proxmox VE node.

🤖 Generated with Claude Code

Adds the `user_management` role, the last role of wave 1. It is copied from the environment repository's local role, plus one behaviour fix (the handback, below) found in review. ## What changed against the source - `meta/main.yml` namespace is `mortis`. - Comments and the README carry no environment references (issue numbers, playbooks, inventory paths and groups, provisioning role names). The sshd role is named without its FQCN (role-independence test). The technical explanations stay. - The molecule scenario calls the role as `mortis.kamino.user_management`, follows the Kamino conventions (`kamino-molecule` header, `scenario.test_sequence`) and drops `provisioner.env`. `prepare.yml` and `verify.yml` are unchanged, so test coverage is the same. - **Fix, `tasks/bootstrap.yml` and `tasks/handback.yml`:** the handback switched the connection back to `ansible_user`, while the role creates `user_management_ansible_user.name`. When the two differed, the root fallback created a user nobody connects as, and the handback then failed after the changes made as root (or later plays connected as the wrong user). The fallback now asserts, before switching to root, that the primary user's name equals `ansible_user` (set as a variable). The handback switches to the user the role created. There is no change where the names are equal, which is the default (`name: "{{ ansible_user }}"`) and the only case in the environment repository (no host overrides `user_management_ansible_user`). - Docs, from review: - `gather_facts: false` is required, otherwise a fresh guest is unreachable before the fallback runs. This is now in the README requirements and example and in the argument spec. - `user_management_authoritative` skips a user whose merged key list is empty, so emptying the list does not remove that user's keys. - `user_management_become_password_hashed` is required unless `user_management_ansible_user` is overridden. - The `defaults/main.yml` comment no longer says `usermod -L`. - Known limits are listed: molecule does not exercise the fallback or the handback (the docker connection always connects), a tag-only run on a fresh host fails at the handback, and the primary user can be set `absent`. - `galaxy.yml`: only the dependency comment names `user_management` as an `ansible.posix` user (`authorized_key`). `ansible.posix >=2.2.0` is already declared. The version is left for the release commit. - Changelog fragment `user-management-role.yml`. The README Roadmap no longer lists wave 1. The `CLAUDE.md` role list is updated. ## Verified - All pre-commit hooks on every commit (ansible-lint production profile with FQCN resolution, yamllint, REUSE, changelog lint, gitleaks) and the pre-push `ansible-test sanity`. - `tests/scripts/test_select_molecule_scenarios.py` (20 tests, including `test_no_role_refers_to_another_role`). - `diff -r` against the source: tasks, defaults, `argument_specs` types and defaults, `prepare.yml` and `verify.yml` match, apart from the fix and comments above. - An independent subagent review (read-only), which found no blockers. Its should-fix items are applied above. It ran `converge.yml --syntax-check` and confirmed that the workflow's collection path resolves the FQCN. ## Not verified - The molecule scenario. It runs here in CI on the `kamino-molecule` runner. This is also the first run without the source's `ANSIBLE_COLLECTIONS_PATH`, so it confirms that `ansible.posix` resolves from the workflow's path. - The root fallback and the handback, including the new assert. The scenario cannot exercise them (docker connection). They are reasoned through only. The environment's last live exercise of the fallback predates the assert. - Converge on 22.04 or a Proxmox VE node. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Claude added 5 commits 2026-11-16 17:29:47 +00:00
Copied from the environment repository's local role. The files are
identical except: galaxy namespace mortis; comments and the README
scrubbed of environment references (issue numbers, playbooks, inventory
groups and group_vars paths, the provisioning roles by name, the history
of the variable rename), with the technical explanation kept; the README
asks for the role by its FQCN, names the run order generically (after the
step that creates the guest, before mortis.kamino.sshd) and its example
play uses mortis.kamino.user_management; the molecule scenario calls the
role by its FQCN, follows the Kamino scenario conventions (kamino-molecule
header, scenario.test_sequence) and no longer sets ANSIBLE_COLLECTIONS_PATH
or ANSIBLE_ROLES_PATH. No variable, default, argument_specs entry or task
logic changed: the key-only root fallback, the handback and
user_management_lock_root_password (default false) are as in the source,
and prepare/verify are unchanged. The role uses ansible.posix
(authorized_key), already a galaxy.yml dependency, so galaxy.yml is
unchanged.

The README Roadmap no longer lists wave 1; CLAUDE.md names the role for
the next release.

Not verified locally: the molecule scenario (it runs on the
kamino-molecule runner in CI) and ansible-test sanity (runs on push).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
The README and the comments of tasks/bootstrap.yml, tasks/handback.yml
and tasks/lock_root.yml named mortis.kamino.sshd, which the
role-independence test refuses in a role's docs. They now name the sshd
role (of this Collection), as the ufw role does for system_baseline. The
role's own FQCN in its README and scenario stays, as in sshd and ufw.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
The comment said usermod -L, but the role replaces the shadow field with "!" and
drops the old hash, which usermod -L would keep.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
From review of the extraction. Documentation only; behaviour is unchanged.
- The play needs gather_facts: false, or a fresh guest is unreachable before
  the root fallback runs (README requirement and example, argument spec).
- user_management_authoritative skips a user whose merged key list is empty,
  so emptying the list keeps that user's existing keys.
- user_management_become_password_hashed is required unless
  user_management_ansible_user is overridden.
- Known limits: molecule does not exercise the fallback or the handback, the
  handback reconnects as ansible_user, a partial tag run on a fresh host
  fails at the handback, and the primary user can be set absent.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
fix(user_management): hand back to the created user and refuse a mismatched fallback
Build / build (pull_request) Successful in 13s
Lint / lint (pull_request) Successful in 34s
Molecule / molecule (pull_request) Successful in 10m5s
ce537fc6b4
The handback switched the connection to ansible_user, while the role creates
user_management_ansible_user.name. When the two differed, the root fallback
created a user nobody connects as, and the handback then failed after the
changes made as root, or later plays connected as the wrong user.

The fallback now asserts, before switching to root, that the primary user's
name equals ansible_user (set as a variable), and the handback switches to
the user the role created. No change where the names are equal (the default).

Also name user_management as a user of ansible.posix in the galaxy.yml comment.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
Defame1297 merged commit bf25a0c0b1 into main 2026-11-16 17:43:34 +00:00
Defame1297 deleted branch feat/user-management-role 2026-11-16 17:43:34 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mortis/Kamino#231