test(roles): run molecule's check step before and after converge
Every role scenario with a converge now runs check right before it (a fresh host) and right after it (a configured host), and a script test fails a scenario without both. pihole and pve_lxc move their second check from after idempotence to after converge to match. The roles that failed under --check on a fresh host get the two allowed guards: cloudflared, docker, gitea, gitea_runner, traefik and user_management. ufw and fail2ban preview only a host where their package is installed, as their READMEs now say. Closes #134 Assisted-by: Claude Code
This commit is contained in:
1 parent
51b38211e7
commit
cf2286b7a7
56 files changed
+202
-35
No files matched your search
@@ -64,7 +64,7 @@ Both are set under the `always` tag.
|
||||
|
||||
## Tests
|
||||
|
||||
`molecule/default` runs in CI only, on two platforms: `${MOLECULE_IMAGE}` (Ubuntu 24.04) and `${MOLECULE_IMAGE_2604}` (Ubuntu 26.04). Prepare creates a stale user to remove, plants an extra key in an existing user's `authorized_keys` for authoritative mode to drop, and sets root's password before converge; the role then locks it. The converge sets the primary user explicitly instead of through the `{{ ansible_user }}` default.
|
||||
`molecule/default` runs in CI only, on two platforms: `${MOLECULE_IMAGE}` (Ubuntu 24.04) and `${MOLECULE_IMAGE_2604}` (Ubuntu 26.04). Prepare creates a stale user to remove, plants an extra key in an existing user's `authorized_keys` for authoritative mode to drop, and sets root's password before converge; the role then locks it. The converge sets the primary user explicitly instead of through the `{{ ansible_user }}` default. It runs `check` before the converge (a fresh host) and after it (a configured host).
|
||||
|
||||
Verify checks:
|
||||
|
||||
@@ -79,6 +79,7 @@ The scenario uses the docker connection, where `wait_for_connection` always succ
|
||||
## Notes
|
||||
|
||||
- Idempotent: yes.
|
||||
- Check mode: `--check` is the supported preview; a play-level `check_mode: true` is not supported. Under `--check` the `authorized_keys` of a user that does not exist yet are skipped, because the user is not created.
|
||||
- `user_management_remove_home` is applied to every user task, so it also passes `remove: true` for present users, which only matters for `state: absent`.
|
||||
- Per-user `authorized_keys` are added to `user_management_default_authorized_keys`. Keys are written only for users whose `state` is present and whose merged list is non-empty. With `user_management_authoritative` true other keys are removed.
|
||||
- `tasks/ssh_keys.yml` hardcodes the `.ssh` path as `/home/<name>/.ssh` and skips creating it for users with `system: true`, but the `authorized_key` task still runs for them (it uses the user's real home), so a system user with keys gets them written.
|
||||
|
||||
@@ -55,13 +55,16 @@ verifier:
|
||||
scenario:
|
||||
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
|
||||
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
|
||||
# A check runs before the converge (fresh host) and after it (configured host).
|
||||
test_sequence:
|
||||
- dependency
|
||||
- cleanup
|
||||
- syntax
|
||||
- create
|
||||
- prepare
|
||||
- check
|
||||
- converge
|
||||
- check
|
||||
- idempotence
|
||||
- side_effect
|
||||
- verify
|
||||
|
||||
@@ -14,6 +14,12 @@
|
||||
- item.state | default('present') == 'present'
|
||||
- not item.system | default(false)
|
||||
|
||||
# Under --check a user the role would create does not exist yet, and authorized_key fails on a missing user.
|
||||
- name: Read the existing users for the check-mode preview
|
||||
ansible.builtin.getent:
|
||||
database: passwd
|
||||
when: ansible_check_mode
|
||||
|
||||
- name: Enforce authorized_keys authoritatively
|
||||
become: true
|
||||
ansible.posix.authorized_key:
|
||||
@@ -25,5 +31,6 @@
|
||||
when:
|
||||
- item.state | default('present') == 'present'
|
||||
- ( user_management_default_authorized_keys + (item.authorized_keys | default([])) ) | length > 0
|
||||
- not ansible_check_mode or item.name in ansible_facts.getent_passwd
|
||||
loop_control:
|
||||
label: "{{ item.name }}"
|
||||
Reference in new issue
Block a user