test(molecule): cover the role with a molecule scenario

The role changed a lot and none of it was verified against a real system so far. The scenario starts one container per
supported distribution family, applies the role and asserts afterwards that the users and groups exist as declared,
that the managed files carry the documented mode, owner and content, that a user without optional settings does not
receive any of the optional files and that a user declared as absent is gone again.

The idempotence step is the actual reason for the scenario. The deterministic password salt and the btrfs device
lookup were changed to stop reporting a change on every run, and only a second converge proves that.

A btrfs home is not covered, because a container has no btrfs filesystem to create a subvolume on.

The ssh key pair the scenario feeds into the role is generated during create and removed again during destroy, so no
private key material ends up in the repository. The generated files are ignored for the case that a destroy never
runs.

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
2026-09-10 09:54:00 +02:00
co-authored by Copilot
parent 00f465e5e1
commit a343205fd3
10 changed files with 393 additions and 1 deletions
+64
View File
@@ -0,0 +1,64 @@
---
# A btrfs home is not covered, a container has no btrfs filesystem to create a subvolume on.
- name: Converge
hosts: all
vars:
unix_groups:
molecule-alice:
# An unquoted gid is an integer, the role has to cope with that.
gid: 4242
state: present
molecule-bob:
state: present
molecule-obsolete:
state: absent
unix_users:
molecule-alice:
state: present
name: Alice
uid: 4242
group: molecule-alice
home: /home/molecule-alice
shell: /bin/bash
password: alice
email: alice@example.local
ssh:
config:
- Host: "*"
StrictHostKeyChecking: "no"
authorized_keys:
- filename: molecule.pub
command: "/usr/bin/true"
envs:
- key: EDITOR
value: vi
private_keys:
- molecule.ed25519.key
netrc:
- machine: hostname.local
login: alice
password: secret
shell_rc_files:
- file: molecule.bashrc
aliases:
- key: dcd
value: docker compose down
envs:
- export: true
key: PATH
value: "${HOME}/bin:${PATH}"
functions:
- name: foo
value: "echo \"bar\""
# Bob declares nothing optional, so none of the optional files may show up in his home.
molecule-bob:
state: present
group: molecule-bob
molecule-dave:
state: absent
tasks:
# The role is included by the name of its directory, which molecule put on the roles path.
- name: Include the role unix-users
ansible.builtin.include_role:
name: unix-users