Compare commits

..
Author SHA1 Message Date
Defame1297 2865573429 test(gitea_runner): fold the disk-pressure run into the failed-download case
Build / build (pull_request) Successful in 38s
Lint / lint (pull_request) Successful in 2m30s
Molecule / molecule (pull_request) Successful in 3m43s
The verify step ran the whole role once only to set the disk threshold to 0. Prune runs
before update in tasks/main.yml, so the failed-download run can carry that input: the
pressure units are removed before the download fails at staging. The exact staging
message the rescue asserts comes only from update.yml, so a prune error still fails it.
The run with the scenario's inputs stays before the remove path, which needs the units back.

The forced re-registration child runs now start once instead of per host: they check only
controller state and group_vars, and run_once gives every host the registered results.

Closes #459

Assisted-by: Claude Code
2026-11-28 20:39:32 +00:00
8 changed files with 80 additions and 83 deletions

No files matched your search

@@ -1,6 +0,0 @@
---
minor_changes:
- >-
traefik - The prerequisites install refreshes the APT cache only when it is older than an hour;
before, every run refreshed it. A consumer who adds an APT source just before the role must
refresh the cache first.
+38 -38
View File
@@ -359,23 +359,26 @@
loop_var: gitea_runner_test_path
# 6.0.2 has a wrong checksum file (prepare.yml): the download must fail before anything is
# stopped, so the runner keeps running 6.0.1.
- name: Verify a failed download leaves the runner running
# stopped, so the runner keeps running 6.0.1. The same run sets the disk threshold to 0: prune
# runs before update, so the pressure units are already removed when the download fails.
- name: Verify a failed download leaves the runner running, and turning the pressure prune off
hosts: all
gather_facts: false
tasks:
- name: Update to a release whose checksum does not match
block:
- name: Include the role with gitea_runner_version 6.0.2
- name: Include the role with gitea_runner_version 6.0.2 and the disk threshold at 0
ansible.builtin.include_role:
name: mortis.kamino.gitea_runner
vars:
gitea_runner_version: 6.0.2
gitea_runner_docker_prune_disk_threshold_percent: 0
- name: Fail because the include returned
ansible.builtin.fail:
msg: The role accepted a binary with a wrong checksum
rescue:
# The message comes only from the staging rescue, so a prune error fails this assert.
- name: The staging failed, and nothing else failed first
ansible.builtin.assert:
that:
@@ -407,6 +410,31 @@
- not gitea_runner_test_staged.stat.exists
quiet: true
- name: Stat the pressure units and script
ansible.builtin.stat:
path: "{{ gitea_runner_test_path }}"
loop:
- /etc/systemd/system/gitea-runner-docker-prune-pressure.service
- /etc/systemd/system/gitea-runner-docker-prune-pressure.timer
- /usr/local/sbin/gitea-runner-docker-prune-disk-check
loop_control:
loop_var: gitea_runner_test_path
register: gitea_runner_test_pressure_off
- name: Ask systemd about the pressure timer after turning it off
ansible.builtin.systemd:
name: gitea-runner-docker-prune-pressure.timer
register: gitea_runner_test_pressure_timer_off
# The module errors for a unit that no longer exists, which is also a pass.
failed_when: false
- name: The pressure units are gone and the timer is not active
ansible.builtin.assert:
that:
- gitea_runner_test_pressure_off.results | map(attribute='stat') | map(attribute='exists') | select | list | length == 0
- gitea_runner_test_pressure_timer_off.status.ActiveState | default('inactive') != 'active'
quiet: true
# Each input assert, through the main entry point. Every one runs in validate.yml, before any
# change.
- name: Verify the input asserts
@@ -448,8 +476,9 @@
label: "{{ gitea_runner_test_refused.name }}"
# The CI guard and the mint-before-drop order of a forced re-registration, through a child
# ansible-playbook against this instance (see force_register.yml). Neither case may touch the
# registration or stop the runner.
# ansible-playbook against one instance (see force_register.yml). Neither case may touch the
# registration or stop the runner. The children run once: what they check is controller state
# and group_vars, the same for every host, and run_once gives every host their results.
- name: Verify the forced re-registration guards
hosts: all
gather_facts: false
@@ -465,6 +494,7 @@
- name: Force a re-registration under each CI variable, as a child process with only that one set
delegate_to: localhost
run_once: true
ansible.builtin.command:
argv:
- ansible-playbook
@@ -497,6 +527,7 @@
- name: Force a re-registration outside CI with no token host, as a child process
delegate_to: localhost
run_once: true
ansible.builtin.command:
argv:
- ansible-playbook
@@ -550,43 +581,12 @@
- gitea_runner_test_unit.status.ActiveState == 'active'
quiet: true
# A threshold of 0 removes the pressure units; the run after it, with the scenario's inputs,
# The failed-download run above removed the pressure units; this run, with the scenario's inputs,
# puts them back, so the remove path below still has them to remove.
- name: Verify turning the pressure prune off
- name: Verify turning the pressure prune on again
hosts: all
gather_facts: false
tasks:
- name: Run the role with the disk threshold at 0
ansible.builtin.include_role:
name: mortis.kamino.gitea_runner
vars:
gitea_runner_docker_prune_disk_threshold_percent: 0
- name: Stat the pressure units and script
ansible.builtin.stat:
path: "{{ gitea_runner_test_path }}"
loop:
- /etc/systemd/system/gitea-runner-docker-prune-pressure.service
- /etc/systemd/system/gitea-runner-docker-prune-pressure.timer
- /usr/local/sbin/gitea-runner-docker-prune-disk-check
loop_control:
loop_var: gitea_runner_test_path
register: gitea_runner_test_pressure_off
- name: Ask systemd about the pressure timer after turning it off
ansible.builtin.systemd:
name: gitea-runner-docker-prune-pressure.timer
register: gitea_runner_test_pressure_timer_off
# The module errors for a unit that no longer exists, which is also a pass.
failed_when: false
- name: The pressure units are gone and the timer is not active
ansible.builtin.assert:
that:
- gitea_runner_test_pressure_off.results | map(attribute='stat') | map(attribute='exists') | select | list | length == 0
- gitea_runner_test_pressure_timer_off.status.ActiveState | default('inactive') != 'active'
quiet: true
- name: Run the role again with the scenario's inputs
ansible.builtin.include_role:
name: mortis.kamino.gitea_runner
+2 -3
View File
@@ -80,14 +80,14 @@ 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 the converge downloads the real Traefik release from GitHub. Prepare runs `mortis.kamino.ufw`, so converge runs only the role. It runs `check` before the converge (on a fresh host) and after it (on the configured host). 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 the converge downloads the real Traefik release 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.
- Files: `traefik.env` mode 0600 owned by root, `dynamic.yml` mode 0600 owned by `traefik`, `traefik.yml` mode 0600, the binary mode 0755; the logrotate configuration, which `logrotate --debug` parses.
- Rendering: the ACME resolvers render when set and are absent when empty; the dashboard is off by default with the extra app routed, and renders behind basicAuth when enabled (a template render, not a running dashboard).
- The service: running and enabled with `NoNewPrivileges`, `MemoryDenyWriteExecute` and `CAP_NET_BIND_SERVICE`, listening on 80 and 443 and redirecting http to https; ufw allows 80 and 443 next to SSH, with the traefik owner tag, in order.
- The update path: it updates to another release with `traefik_update` (download from local `file://` stand-in releases, checksum check and swap) and asserts the version, an active unit and no leftovers. It leaves the stand-in stub installed, so nothing after it asserts real Traefik behaviour.
- The update path: it updates to another release and back with `traefik_update` (download from local `file://` stand-in releases, checksum check and swap) and asserts the version, an active unit and no leftovers. It leaves the stand-in stub installed, so nothing after it asserts real Traefik behaviour.
- The remove path, last: unit and binary are deleted, the service is no longer active, and only the traefik ufw rules are removed.
The scenario disables the namespace-based sandboxing and the `User=` switch with a drop-in because its container is unprivileged, so that sandboxing is not covered by CI. Certificate issuance is not covered: the Cloudflare credentials are dummies.
@@ -96,7 +96,6 @@ The scenario disables the namespace-based sandboxing and the `User=` switch with
- 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 does not refresh an APT cache younger than an hour, so a package from a source you add just before the role (`ansible.builtin.deb822_repository` does not refresh) needs your own cache refresh first.
- 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.
+5 -3
View File
@@ -1,10 +1,12 @@
---
# Role variables come from the inventory group_vars in molecule.yml, so the idempotence step
# reruns converge with identical configuration; verify's plays override only what they test.
# mortis.kamino.ufw runs in prepare.yml, so only traefik counts toward idempotence. Facts are
# off: neither the role nor the roles it includes reads any.
# The base ufw play comes first: traefik passes its rules through the mortis.kamino.ufw
# service_rules entry point, which needs ufw installed and active. ufw_rules comes from the
# same group_vars (the SSH allow rule the lock-out guard requires).
- name: Converge
hosts: all
gather_facts: false
gather_facts: true
roles:
- role: mortis.kamino.ufw
- role: mortis.kamino.traefik
+6 -7
View File
@@ -3,7 +3,7 @@
# (MOLECULE_IMAGE) and molecule-ubuntu2604 (MOLECULE_IMAGE_2604) images, pinned in
# .gitea/workflows/molecule.yml. Needs outbound network, unlike most scenarios: the role installs
# packages with apt and the converge downloads the Traefik release from GitHub (verify's update
# path uses a file:// stand-in built by prepare.yml). No privileged mode: systemd needs a writable
# path uses file:// stand-ins built by prepare.yml). No privileged mode: systemd needs a writable
# cgroup and the firewall tools need NET_ADMIN.
driver:
name: docker
@@ -44,10 +44,9 @@ platforms:
- apparmor=unconfined
provisioner:
name: ansible
# One source for the prepare plays that read them, converge.yml and verify.yml. The role renders
# traefik.yml before its dashboard-auth collision check, so that guard play with other values
# would change it (and restart Traefik) before verify's assertions; converge's values must also
# stay fixed for idempotence.
# One source for every play in converge.yml and verify.yml. The role renders traefik.yml before
# its dashboard-auth collision check, so that guard play with other values would change it (and
# restart Traefik) before verify's assertions; converge's values must also stay fixed for idempotence.
inventory:
group_vars:
all:
@@ -56,8 +55,8 @@ provisioner:
traefik_cloudflare_email: [email protected]
traefik_cloudflare_api_token: molecule-not-a-token
traefik_domain: example.test
# Any release other than the role default: verify's update path goes there, from the
# stand-in prepare.yml builds.
# Any release other than the role default: verify's update path goes there and back,
# from the stand-ins prepare.yml builds.
traefik_verify_other_version: v3.7.18
ufw_rules:
- {rule: allow, port: 22, proto: tcp, comment: ssh}
+19 -18
View File
@@ -41,34 +41,26 @@
ReadWritePaths=
User=
# traefik passes its rules through the mortis.kamino.ufw service_rules entry point, which needs ufw
# installed and active. ufw_rules comes from the inventory group_vars (the SSH allow rule the
# lock-out guard requires); the ufw scenario tests that role, so it runs once here, not in converge.
- name: Install and enable ufw
hosts: all
gather_facts: false
roles:
- role: mortis.kamino.ufw
# A stand-in release for verify's update path, behind a file:// URL: the role's download, checksum
# check and swap run unchanged, without fetching another real release per host. The converge
# Stand-in releases for verify's update path, behind file:// URLs: the role's download, checksum
# check and swap run unchanged, without fetching two more real releases per host. The converge
# still downloads the real role default from GitHub.
- name: Prepare the stand-in release
- name: Prepare the stand-in releases
hosts: all
gather_facts: false
vars_files:
- ../../defaults/main.yml
vars:
traefik_test_release: "{{ traefik_verify_other_version }}"
tasks:
- name: Create the stand-in release directory
- name: Create a directory per stand-in release
ansible.builtin.file:
path: "/opt/molecule-download/{{ traefik_test_release }}"
state: directory
mode: "0755"
loop: ["{{ traefik_verify_other_version }}", "{{ traefik_version }}"]
loop_control:
loop_var: traefik_test_release
# Answers `version` like Traefik and otherwise stays up like the service.
- name: Write the stand-in binary
- name: Write the stand-in binaries
ansible.builtin.copy:
dest: "/opt/molecule-download/{{ traefik_test_release }}/traefik"
mode: "0755"
@@ -78,16 +70,25 @@
version) echo "Version: {{ traefik_test_release | regex_replace('^v', '') }}" ;;
*) exec sleep infinity ;;
esac
loop: ["{{ traefik_verify_other_version }}", "{{ traefik_version }}"]
loop_control:
loop_var: traefik_test_release
- name: Pack the stand-in archive
- name: Pack the stand-in archives
ansible.builtin.command:
argv: [tar, -czf, "{{ traefik_test_archive }}", -C, "/opt/molecule-download/{{ traefik_test_release }}", traefik]
creates: "{{ traefik_test_archive }}"
vars:
traefik_test_archive: "/opt/molecule-download/{{ traefik_test_release }}/traefik_{{ traefik_test_release }}_{{ traefik_os }}_{{ traefik_arch }}.tar.gz"
loop: ["{{ traefik_verify_other_version }}", "{{ traefik_version }}"]
loop_control:
loop_var: traefik_test_release
- name: Write the checksums file in the release format
- name: Write the checksums files in the release format
ansible.builtin.shell:
cmd: sha256sum traefik_*.tar.gz > traefik_{{ traefik_test_release }}_checksums.txt
chdir: "/opt/molecule-download/{{ traefik_test_release }}"
creates: "traefik_{{ traefik_test_release }}_checksums.txt"
loop: ["{{ traefik_verify_other_version }}", "{{ traefik_version }}"]
loop_control:
loop_var: traefik_test_release
+10 -7
View File
@@ -293,11 +293,11 @@
traefik_ufw_key_443: "{{ ('allow|443|||||in' | hash('sha1'))[:10] }}"
traefik_ufw_tagged: "{{ traefik_ufw_added.stdout_lines | select('match', '^ufw ') | select('search', 'ansible-ufw') | list }}"
# A version bump through the update path and mortis.kamino._binary_update: to another release
# with traefik_update, from prepare.yml's stand-in. One bump covers the download, checksum check
# and swap. After the idempotence step, because it changes the binary, and before the remove path.
# A version bump through the update path and mortis.kamino._binary_update: down to another
# release and back to the role default, both with traefik_update, from prepare.yml's stand-ins.
# After the idempotence step, because each run changes the binary, and before the remove path.
# It leaves the stand-in stub installed, so nothing after it may assert real Traefik behaviour.
- name: Verify the update path with a stand-in release
- name: Verify the update path with stand-in releases
hosts: all
gather_facts: false
vars_files:
@@ -309,10 +309,13 @@
fail_msg: Move traefik_verify_other_version off the role default ({{ traefik_version }}).
quiet: true
- name: Update to the other release
- name: Update to the other release, then back to the role default
ansible.builtin.include_tasks: tasks/update_and_check.yml
vars:
traefik_verify_target: "{{ traefik_verify_other_version }}"
loop:
- "{{ traefik_verify_other_version }}"
- "{{ traefik_version }}"
loop_control:
loop_var: traefik_verify_target
# The remove path. Last on purpose: it destroys what the plays above verify, and it runs
# once, outside the idempotence step (a converge play that changed state would fail that step).
-1
View File
@@ -11,7 +11,6 @@
- logrotate
state: present
update_cache: true
cache_valid_time: 3600
tags: [traefik, prereqs, always]
- name: Create Traefik group