Files
Defame1297andClaude Opus 5.5 2713753039 feat(user_management): add the user_management role
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
2026-11-16 17:12:05 +00:00

103 lines
3.4 KiB
YAML

---
- name: Verify
hosts: all
gather_facts: false
tasks:
- name: Read the account databases
ansible.builtin.getent:
database: passwd
- name: The removed user is gone
ansible.builtin.assert:
that: "'um-olduser' not in getent_passwd"
quiet: true
- name: Read group membership
ansible.builtin.command: "id -nG {{ item }}"
loop: [um-admin, um-alice]
register: user_management_verify_groups
changed_when: false
- name: Both users are in the sudo group
ansible.builtin.assert:
that:
- "'sudo' in item.stdout.split()"
quiet: true
loop: "{{ user_management_verify_groups.results }}"
loop_control:
label: "{{ item.item }}"
- name: Stat the removed user's home
ansible.builtin.stat:
path: /home/um-olduser
register: user_management_verify_olduser_home
- name: The removed user's home is gone
ansible.builtin.assert:
that: not user_management_verify_olduser_home.stat.exists
quiet: true
- name: Read the authorized_keys files
ansible.builtin.slurp:
src: "/home/{{ item }}/.ssh/authorized_keys"
loop: [um-admin, um-alice]
register: user_management_verify_keys
- name: The authorized_keys files hold exactly the configured keys (the planted extra key is gone)
ansible.builtin.assert:
that:
- (user_management_verify_keys.results[0].content | b64decode).split('\n') | select | list == [user_management_test_admin_key]
- (user_management_verify_keys.results[1].content | b64decode).split('\n') | select | list == [user_management_test_alice_key]
- "'rogue-extra' not in (user_management_verify_keys.results[1].content | b64decode)"
quiet: true
- name: Validate the sudoers configuration
ansible.builtin.command: visudo -c
changed_when: false
- name: Show what the sudo users may run
ansible.builtin.command: "sudo -l -U {{ item }}"
loop: [um-admin, um-alice]
register: user_management_verify_sudo
changed_when: false
- name: Membership of the sudo group grants sudo
ansible.builtin.assert:
that:
- "'(ALL : ALL) ALL' in item.stdout or '(ALL) ALL' in item.stdout"
quiet: true
loop: "{{ user_management_verify_sudo.results }}"
loop_control:
label: "{{ item.item }}"
- name: The ansible user is not locked out (key present, account usable)
ansible.builtin.assert:
that:
- user_management_test_admin_key in (user_management_verify_keys.results[0].content | b64decode)
- getent_passwd['um-admin'][5] != '/usr/sbin/nologin'
quiet: true
- name: Read root's shadow entry
become: true
ansible.builtin.getent:
database: shadow
key: root
- name: Root's password is locked
ansible.builtin.assert:
that:
- getent_shadow['root'][0] == '!'
quiet: true
- name: Read root's authorized_keys
ansible.builtin.slurp:
src: /root/.ssh/authorized_keys
register: user_management_verify_root_keys
- name: The lock left root's key and shell alone
ansible.builtin.assert:
that:
- (user_management_verify_root_keys.content | b64decode) is search('root-key$', multiline=true)
- getent_passwd['root'][5] == '/bin/bash'
quiet: true