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
@@ -79,7 +79,7 @@ Update or remove: pass `-e traefik_update=true`, or `-e "traefik_remove=true tra
|
||||
|
||||
## Tests
|
||||
|
||||
The `default` molecule scenario runs in CI only, on two platforms: `${MOLECULE_IMAGE}` (Ubuntu 24.04) and `${MOLECULE_IMAGE_2604}` (Ubuntu 26.04). It needs outbound network: the role installs packages with apt and downloads real Traefik releases from GitHub. Converge runs `mortis.kamino.ufw`, then the role. Verify covers:
|
||||
The `default` molecule scenario runs in CI only, on two platforms: `${MOLECULE_IMAGE}` (Ubuntu 24.04) and `${MOLECULE_IMAGE_2604}` (Ubuntu 26.04). It needs outbound network: the role installs packages with apt and downloads real Traefik releases from GitHub. Converge runs `mortis.kamino.ufw`, then the role. It runs `check` before the converge (on a fresh host) and after it (on the configured host). Verify covers:
|
||||
|
||||
- The input guards, first: one play expects the failure message containing `unauthenticated Traefik dashboard` (the dashboard guard: enabled without valid `user:hash` users); the next expects `collides with the middleware`, raised by the dashboard-auth collision assert, which runs whenever users are set, also with the dashboard off.
|
||||
- The install: the pinned version runs, and only the binary is left from the archive.
|
||||
@@ -94,6 +94,7 @@ The scenario disables the namespace-based sandboxing and the `User=` switch with
|
||||
## Notes
|
||||
|
||||
- Idempotent: yes.
|
||||
- Check mode: `--check` is the supported preview; a play-level `check_mode: true` is not supported. On a host without the Traefik binary, the ACME file permissions, the service start and its running check, the `Restart Traefik` handler and the `traefik_update` tasks are skipped under `--check`, because nothing is extracted and the unit file is only simulated.
|
||||
- The role is not a state selector. `main.yml` runs prerequisites and configure unless `traefik_remove` is true; install runs only when the binary is absent; update only when `traefik_update` is true; remove only when `traefik_remove` is true, and then every other task in `main.yml` is skipped.
|
||||
- Download integrity: the archive SHA-256 must appear in the release's checksum file or the play fails.
|
||||
- Secrets: `traefik.env` (mode 0600, root) and `dynamic.yml` are rendered with `no_log: true`, and no backups are kept, so `--diff` never shows them. `dynamic.yml` may hold dashboard htpasswd hashes.
|
||||
|
||||
@@ -9,3 +9,5 @@
|
||||
ansible.builtin.systemd:
|
||||
name: traefik
|
||||
state: restarted
|
||||
# Under --check on a first install there is no unit to restart yet.
|
||||
when: not ansible_check_mode or traefik_installed | bool
|
||||
@@ -68,13 +68,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
|
||||
|
||||
@@ -196,6 +196,8 @@
|
||||
name: traefik
|
||||
enabled: true
|
||||
state: started
|
||||
# Under --check on a first install the unit file is only simulated, so systemd would not find it.
|
||||
when: not ansible_check_mode or traefik_installed | bool
|
||||
tags: [traefik, configure]
|
||||
|
||||
- name: Check Traefik service status
|
||||
@@ -208,5 +210,7 @@
|
||||
- name: Fail if Traefik service is not running
|
||||
ansible.builtin.fail:
|
||||
msg: "Traefik service is not running"
|
||||
when: traefik_service_status.status.ActiveState != "active"
|
||||
when:
|
||||
- not ansible_check_mode or traefik_installed | bool
|
||||
- traefik_service_status.status.ActiveState != "active"
|
||||
tags: [traefik, configure, health]
|
||||
@@ -21,6 +21,7 @@
|
||||
cmd: touch {{ traefik_acme_file }}
|
||||
args:
|
||||
creates: "{{ traefik_acme_file }}"
|
||||
register: __traefik_acme_touch
|
||||
tags: [traefik, install, binary, update]
|
||||
|
||||
- name: Ensure correct permissions on ACME file
|
||||
@@ -30,6 +31,8 @@
|
||||
owner: "{{ traefik_user }}"
|
||||
group: "{{ traefik_user }}"
|
||||
mode: "0600"
|
||||
# Under --check the touch above is skipped, and the file module fails on a missing file.
|
||||
when: not ansible_check_mode or __traefik_acme_touch is not changed
|
||||
tags: [traefik, install, binary, update]
|
||||
|
||||
- name: Install the Traefik binary
|
||||
@@ -49,4 +52,6 @@
|
||||
that:
|
||||
- traefik_binary.stat.exists
|
||||
fail_msg: "Traefik binary not found after extraction"
|
||||
# Nothing is extracted under --check.
|
||||
when: not ansible_check_mode
|
||||
tags: [traefik, install, binary, health, update]
|
||||
@@ -63,4 +63,6 @@
|
||||
when:
|
||||
- traefik_update | bool
|
||||
- not (traefik_remove | default(false) | bool)
|
||||
# Under --check on a first install no binary is extracted, so the update would try to swap a service that does not exist.
|
||||
- not ansible_check_mode or traefik_installed | bool
|
||||
tags: [traefik, update]
|
||||
Reference in new issue
Block a user