feat(traefik): skip a fresh apt refresh and trim the scenario's repeated work
Build / build (pull_request) Successful in 1m16s
Lint / lint (pull_request) Successful in 5m47s
Molecule / molecule (pull_request) Successful in 8m58s

The prerequisites install takes only distribution packages and runs
before any source is added, yet refreshed the APT cache on every run.
It now passes cache_valid_time: 3600, as docker, system_baseline and
user_management already do; the README tells a consumer who adds a
source just before the role to refresh the cache themselves.

The default scenario repeated work other steps already cover. Verify
now exercises the update path once, to the other release, so prepare
builds only that stand-in; the role default's stand-in was used only
by the way back. mortis.kamino.ufw moves to prepare, as the ufw
scenario tests it, so converge and idempotence run only traefik, with
fact gathering off since none of the roles reads facts.

Closes #458

Assisted-by: Claude Code
This commit is contained in:
Defame1297 committed 2026-11-28 21:39:33 +00:00
1 parent 716baa19c7
commit 7bc3cc6bdf
7 files changed
+45 -42

No files matched your search

+3 -5
View File
@@ -1,12 +1,10 @@
---
# 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.
# 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).
# 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.
- name: Converge
hosts: all
gather_facts: true
gather_facts: false
roles:
- role: mortis.kamino.ufw
- role: mortis.kamino.traefik
+7 -6
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 file:// stand-ins built by prepare.yml). No privileged mode: systemd needs a writable
# path uses a file:// stand-in built by prepare.yml). No privileged mode: systemd needs a writable
# cgroup and the firewall tools need NET_ADMIN.
driver:
name: docker
@@ -44,9 +44,10 @@ platforms:
- apparmor=unconfined
provisioner:
name: ansible
# 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.
# 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.
inventory:
group_vars:
all:
@@ -55,8 +56,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 and back,
# from the stand-ins prepare.yml builds.
# Any release other than the role default: verify's update path goes there, from the
# stand-in prepare.yml builds.
traefik_verify_other_version: v3.7.18
ufw_rules:
- {rule: allow, port: 22, proto: tcp, comment: ssh}
+18 -19
View File
@@ -41,26 +41,34 @@
ReadWritePaths=
User=
# 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
# 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
# still downloads the real role default from GitHub.
- name: Prepare the stand-in releases
- name: Prepare the stand-in release
hosts: all
gather_facts: false
vars_files:
- ../../defaults/main.yml
vars:
traefik_test_release: "{{ traefik_verify_other_version }}"
tasks:
- name: Create a directory per stand-in release
- name: Create the stand-in release directory
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 binaries
- name: Write the stand-in binary
ansible.builtin.copy:
dest: "/opt/molecule-download/{{ traefik_test_release }}/traefik"
mode: "0755"
@@ -70,25 +78,16 @@
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 archives
- name: Pack the stand-in archive
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 files in the release format
- name: Write the checksums file 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
+7 -10
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: 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.
# 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.
# It leaves the stand-in stub installed, so nothing after it may assert real Traefik behaviour.
- name: Verify the update path with stand-in releases
- name: Verify the update path with a stand-in release
hosts: all
gather_facts: false
vars_files:
@@ -309,13 +309,10 @@
fail_msg: Move traefik_verify_other_version off the role default ({{ traefik_version }}).
quiet: true
- name: Update to the other release, then back to the role default
- name: Update to the other release
ansible.builtin.include_tasks: tasks/update_and_check.yml
loop:
- "{{ traefik_verify_other_version }}"
- "{{ traefik_version }}"
loop_control:
loop_var: traefik_verify_target
vars:
traefik_verify_target: "{{ traefik_verify_other_version }}"
# 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).