From 0eade70b5616585def96985c22842ac1561890b1 Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Fri, 27 Nov 2026 14:10:53 +0000 Subject: [PATCH 1/4] test(tailscale): let apt reuse downloaded packages in the default scenario The Ubuntu base image's /etc/apt/apt.conf.d/docker-clean deletes every downloaded .deb after an install, so verify's downgrade, update and reinstalls fetched tailscale from pkgs.tailscale.com again each time. A prepare playbook removes it; the install from the real repository stays, and apt still checks a cached .deb against the repository's hashes. Assisted-by: Claude Code:claude-opus-5-5 --- roles/tailscale/molecule/default/prepare.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 roles/tailscale/molecule/default/prepare.yml diff --git a/roles/tailscale/molecule/default/prepare.yml b/roles/tailscale/molecule/default/prepare.yml new file mode 100644 index 0000000..0f3a21a --- /dev/null +++ b/roles/tailscale/molecule/default/prepare.yml @@ -0,0 +1,11 @@ +--- +# The base image's docker-clean deletes each downloaded .deb after an install, so verify's update and +# reinstalls would fetch tailscale again; without it apt reuses the cached .deb after checking its hash. +- name: Prepare + hosts: all + gather_facts: false + tasks: + - name: Keep downloaded packages in the apt cache + ansible.builtin.file: + path: /etc/apt/apt.conf.d/docker-clean + state: absent From 1048628cc4a59cff583ee5611ad05297eec61db9 Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Fri, 27 Nov 2026 14:14:56 +0000 Subject: [PATCH 2/4] feat(cloudflared): add cloudflared_tunnel_lookup_delay input The tunnel lookup retries a 404 three times, 5 seconds apart, before it trusts it. The new input sets that delay (default 5, as before), and validate.yml refuses a negative value. The Molecule failure cases pass 0: the stub API answers at once, and the three retries still run. Assisted-by: Claude Code:claude-opus-5-5 --- changelogs/fragments/cloudflared-tunnel-lookup-delay.yml | 6 ++++++ roles/cloudflared/README.md | 1 + roles/cloudflared/defaults/main.yml | 2 ++ roles/cloudflared/meta/argument_specs.yml | 7 +++++++ roles/cloudflared/molecule/default/tasks/failed_run.yml | 2 ++ roles/cloudflared/molecule/default/verify.yml | 5 ++++- roles/cloudflared/tasks/configure.yml | 2 +- roles/cloudflared/tasks/validate.yml | 6 ++++++ 8 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/cloudflared-tunnel-lookup-delay.yml diff --git a/changelogs/fragments/cloudflared-tunnel-lookup-delay.yml b/changelogs/fragments/cloudflared-tunnel-lookup-delay.yml new file mode 100644 index 0000000..18e305f --- /dev/null +++ b/changelogs/fragments/cloudflared-tunnel-lookup-delay.yml @@ -0,0 +1,6 @@ +--- +minor_changes: + - >- + cloudflared - New input ``cloudflared_tunnel_lookup_delay``, the seconds between the three + retries of a 404 from the tunnel lookup while a new tunnel may not be visible yet. The default + is 5, as before. diff --git a/roles/cloudflared/README.md b/roles/cloudflared/README.md index 2909705..695fad2 100644 --- a/roles/cloudflared/README.md +++ b/roles/cloudflared/README.md @@ -32,6 +32,7 @@ The role targets Ubuntu hosts that run the tunnel daemon, not Proxmox nodes, so | `cloudflared_zone_name` | `""` (asserted while `cloudflared_manage_dns`) | Zone of the ingress hostnames. | | `cloudflared_allow_dns_overwrite` | `[]` | Hostnames whose existing non-tunnel DNS record may be overwritten. | | `cloudflared_api_base_url` | `https://api.cloudflare.com/client/v4` | Cloudflare API base URL for the role's `uri` calls, no trailing slash. | +| `cloudflared_tunnel_lookup_delay` | `5` | Seconds between the three retries of a 404 from the tunnel lookup, at least 0. | | `cloudflared_tunnel_name` | `{{ inventory_hostname }}-tunnel` | Tunnel name used by the `mint` entry point. | | `cloudflared_version` | pinned in `defaults/main.yml` | Release tag, `YYYY.M.P`. | | `cloudflared_sha256_amd64` | pinned | SHA-256 of the amd64 binary. Update with the version. | diff --git a/roles/cloudflared/defaults/main.yml b/roles/cloudflared/defaults/main.yml index 3c52855..a255a0c 100644 --- a/roles/cloudflared/defaults/main.yml +++ b/roles/cloudflared/defaults/main.yml @@ -17,6 +17,8 @@ cloudflared_config_dir: "/etc/cloudflared" cloudflared_service_unit: "/etc/systemd/system/cloudflared.service" cloudflared_api_base_url: "https://api.cloudflare.com/client/v4" +# Seconds between the three retries of a 404 from the tunnel lookup. +cloudflared_tunnel_lookup_delay: 5 cloudflared_tunnel_name: "{{ inventory_hostname }}-tunnel" diff --git a/roles/cloudflared/meta/argument_specs.yml b/roles/cloudflared/meta/argument_specs.yml index 07966e6..d84b66e 100644 --- a/roles/cloudflared/meta/argument_specs.yml +++ b/roles/cloudflared/meta/argument_specs.yml @@ -102,6 +102,13 @@ argument_specs: Base URL of the Cloudflare API, without a trailing slash. Prefixed to every request the role makes with C(ansible.builtin.uri) (tunnel lookup and delete, zone lookup and DNS record listing). The C(community.general.cloudflare_dns) tasks always use the public endpoint. + cloudflared_tunnel_lookup_delay: + type: int + default: 5 + description: + - >- + Seconds between the three retries of the tunnel lookup when Cloudflare answers 404, which right + after a mint can be read-after-write lag rather than a deleted tunnel. At least 0. cloudflared_tunnel_name: type: raw description: diff --git a/roles/cloudflared/molecule/default/tasks/failed_run.yml b/roles/cloudflared/molecule/default/tasks/failed_run.yml index b94f8b0..78e4eba 100644 --- a/roles/cloudflared/molecule/default/tasks/failed_run.yml +++ b/roles/cloudflared/molecule/default/tasks/failed_run.yml @@ -23,6 +23,8 @@ cloudflared_user: "{{ cloudflared_test_case.vars.cloudflared_user | default('cloudflared') }}" cloudflared_install_dir: "{{ cloudflared_test_case.vars.cloudflared_install_dir | default('/usr/local/bin') }}" cloudflared_config_dir: "{{ cloudflared_test_case.vars.cloudflared_config_dir | default('/etc/cloudflared') }}" + # The stub answers at once, so the retries need no wait; they still run. + cloudflared_tunnel_lookup_delay: "{{ cloudflared_test_case.vars.cloudflared_tunnel_lookup_delay | default(0) }}" # Only reached when the include returned. The message must not contain the expected # text, so the rescue below cannot mistake it for the failure under test. diff --git a/roles/cloudflared/molecule/default/verify.yml b/roles/cloudflared/molecule/default/verify.yml index 88f0547..4d4642f 100644 --- a/roles/cloudflared/molecule/default/verify.yml +++ b/roles/cloudflared/molecule/default/verify.yml @@ -157,6 +157,9 @@ - name: tunnel-id-not-uuid vars: {cloudflared_tunnel_id: not-a-uuid} expect: must be a lowercase UUID + - name: lookup-delay-negative + vars: {cloudflared_tunnel_lookup_delay: -1} + expect: cloudflared_tunnel_lookup_delay must be a whole number of seconds, at least 0 - name: tunnel-not-minted vars: {cloudflared_tunnel_id: ""} expect: run the mint entry point first @@ -172,7 +175,7 @@ - name: tunnel-deleted vars: {cloudflared_tunnel_id: 6f1a6e2c-0000-4000-8000-000000000002} expect: no longer exists on Cloudflare - # Retried three times, 5 s apart, before the 404 is trusted. + # Retried three times (with no delay here) before the 404 is trusted. - name: tunnel-unknown vars: {cloudflared_tunnel_id: 6f1a6e2c-0000-4000-8000-00000000000f} expect: (HTTP 404) diff --git a/roles/cloudflared/tasks/configure.yml b/roles/cloudflared/tasks/configure.yml index 3fd0c3c..13ceaa4 100644 --- a/roles/cloudflared/tasks/configure.yml +++ b/roles/cloudflared/tasks/configure.yml @@ -20,7 +20,7 @@ # briefly before trusting it. until: __cloudflared_tunnel_lookup.status | default(0) == 200 retries: 3 - delay: 5 + delay: "{{ cloudflared_tunnel_lookup_delay }}" # Running out of retries fails the task whatever its status, and no_log would hide why: the # two tasks below fail instead, with the re-mint instructions for a 404. ignore_errors: true # noqa: ignore-errors diff --git a/roles/cloudflared/tasks/validate.yml b/roles/cloudflared/tasks/validate.yml index af69983..64f5562 100644 --- a/roles/cloudflared/tasks/validate.yml +++ b/roles/cloudflared/tasks/validate.yml @@ -63,6 +63,12 @@ newline or %, and the two directories must be absolute paths. quiet: true +- name: Require a non-negative tunnel lookup delay + ansible.builtin.assert: + that: cloudflared_tunnel_lookup_delay | int(-1) >= 0 + fail_msg: cloudflared_tunnel_lookup_delay must be a whole number of seconds, at least 0. + quiet: true + # The role never creates the tunnel on its main entry point. Defined and empty (or null) counts # as missing, as in the mint entry point, so the two cannot disagree. - name: Require the minted tunnel secrets From 0973f39831ddc61d48d356166e217410147a61f1 Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Fri, 27 Nov 2026 15:10:32 +0000 Subject: [PATCH 3/4] feat: refresh the APT cache on distribution-only installs when stale The docker prerequisites and the system_baseline packages install only from the distribution's sources, yet refreshed the APT cache on every run. They now pass cache_valid_time: 3600, as the system_baseline update task and user_management already do. The docker and tailscale installs from the role's own APT source keep refreshing on every run, so a run that wrote the source line but failed to fetch its lists heals on the next run. The update entry points are unchanged. The system_baseline README tells a consumer who adds a source just before the role to refresh the cache themselves. Assisted-by: Claude Code:claude-opus-5-5 --- changelogs/fragments/apt-cache-valid-time.yml | 7 +++++++ roles/docker/tasks/install.yml | 2 ++ roles/system_baseline/README.md | 1 + roles/system_baseline/tasks/packages.yml | 1 + 4 files changed, 11 insertions(+) create mode 100644 changelogs/fragments/apt-cache-valid-time.yml diff --git a/changelogs/fragments/apt-cache-valid-time.yml b/changelogs/fragments/apt-cache-valid-time.yml new file mode 100644 index 0000000..5f0df7c --- /dev/null +++ b/changelogs/fragments/apt-cache-valid-time.yml @@ -0,0 +1,7 @@ +--- +minor_changes: + - >- + docker, system_baseline - The install tasks that only use the distribution's sources (docker's + prerequisites, system_baseline's packages) refresh the APT cache only when it is older than an + hour; before, every run refreshed it. Installs from a role's own APT source still refresh it on + every run. diff --git a/roles/docker/tasks/install.yml b/roles/docker/tasks/install.yml index 710fb2e..22497a0 100644 --- a/roles/docker/tasks/install.yml +++ b/roles/docker/tasks/install.yml @@ -7,6 +7,7 @@ - curl state: present update_cache: true + cache_valid_time: 3600 tags: [docker, install] - name: Ensure APT keyrings directory exists @@ -40,6 +41,7 @@ ansible.builtin.apt: name: "{{ docker_packages }}" state: present + # Always refreshed: a run that wrote the source line but failed to fetch its lists heals here. update_cache: true register: __docker_packages notify: Restart docker diff --git a/roles/system_baseline/README.md b/roles/system_baseline/README.md index a5f2dd9..c3054c0 100644 --- a/roles/system_baseline/README.md +++ b/roles/system_baseline/README.md @@ -159,6 +159,7 @@ system_baseline_extra_remove_packages: [telnet] ``` - Each item is a Debian package name: lower-case letters, digits, `+`, `-` and `.`, two or more characters, starting with a letter or digit and not ending in `-` (apt reads a trailing minus as a removal). Anything else stops the run. Duplicates of the profile list are harmless. +- 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. - An extra counts wherever the role looks for a package in the list: an extra `tmux` enables the tmux snippet and an extra `unattended-upgrades` the unattended-upgrades tasks, as a profile package does. - A package that one input installs and another purges stops the run before any change: `system_baseline_extra_packages` against `system_baseline_remove_packages` or `system_baseline_extra_remove_packages`, and `system_baseline_extra_remove_packages` against `system_baseline_essential_packages`. The resolved lists are not checked against each other, so a consumer's own overlap there behaves as before. diff --git a/roles/system_baseline/tasks/packages.yml b/roles/system_baseline/tasks/packages.yml index 1439741..149388b 100644 --- a/roles/system_baseline/tasks/packages.yml +++ b/roles/system_baseline/tasks/packages.yml @@ -4,6 +4,7 @@ name: "{{ __system_baseline_install_packages }}" state: present update_cache: true + cache_valid_time: 3600 become: true - name: Gather installed packages From ab0ce421cc1bfd4eda2b64efc9b234e87952174c Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Fri, 27 Nov 2026 14:58:42 +0000 Subject: [PATCH 4/4] feat(traefik): add traefik_release_url for a release mirror The archive and checksums URLs were hardcoded to the GitHub releases. traefik_release_url (default: the GitHub release directory of traefik_version, as before) lets a host download from a mirror. The Molecule scenario uses it: verify's update path now downloads stand-in releases that prepare.yml builds under /opt/molecule-download (a stub binary answering `version`, its archive and a sha256sum checksums file), so it no longer fetches two more real releases per host. The converge still downloads the real release from GitHub, which keeps the default URL proven. traefik_verify_other_version moves to the scenario's group vars so prepare and verify share it. The update path leaves the stub installed, which the README and verify now state. Verify replaces the fixed 15 s pause with a poll (30 x 2 s) for an "Unable to obtain ACME certificate" log line stamped at or after the running process's ExecMainStartTimestamp, so a line left by the process converge restarted does not count. It fails closed on a missing start time, a missing line or an unparseable stamp. It then asserts NRestarts is 0, since Restart=always would hide a crash. Assisted-by: Claude Code:claude-opus-5-5 --- changelogs/fragments/traefik-release-url.yml | 5 ++ roles/traefik/README.md | 5 +- roles/traefik/defaults/main.yml | 2 + roles/traefik/meta/argument_specs.yml | 8 +++ roles/traefik/molecule/default/molecule.yml | 8 ++- roles/traefik/molecule/default/prepare.yml | 52 +++++++++++++++++++ .../default/tasks/update_and_check.yml | 1 + roles/traefik/molecule/default/verify.yml | 49 +++++++++++++---- roles/traefik/tasks/binary/download.yml | 4 +- 9 files changed, 117 insertions(+), 17 deletions(-) create mode 100644 changelogs/fragments/traefik-release-url.yml diff --git a/changelogs/fragments/traefik-release-url.yml b/changelogs/fragments/traefik-release-url.yml new file mode 100644 index 0000000..e1e1961 --- /dev/null +++ b/changelogs/fragments/traefik-release-url.yml @@ -0,0 +1,5 @@ +--- +minor_changes: + - >- + traefik - New input ``traefik_release_url`` sets where the release archive and checksums are + downloaded from, for a mirror (default: the GitHub releases, as before). diff --git a/roles/traefik/README.md b/roles/traefik/README.md index 48503a1..4658ac2 100644 --- a/roles/traefik/README.md +++ b/roles/traefik/README.md @@ -30,6 +30,7 @@ The role targets Ubuntu hosts that run the reverse proxy, not Proxmox nodes, so | `traefik_version` | pinned in `defaults/main.yml` | no | Release tag to install. | | `traefik_arch` | `amd64` | no | Archive architecture. | | `traefik_os` | `linux` | no | Archive OS. | +| `traefik_release_url` | github.com release directory of `traefik_version` | no | Directory URL of the archive and its checksums file, no trailing slash (templated). | | `traefik_archive_name` | `traefik___.tar.gz` | no | Archive file name (templated). | | `traefik_local_archive` | `/tmp/traefik.tar.gz` | no | Download destination, removed after extraction. | | `traefik_bin_path` | `/usr/local/bin/traefik` | no | Binary path used by the unit and version checks; only the `traefik` file of the archive is extracted into its directory, so the file name must stay `traefik`. Only the `traefik` file is extracted, so the archive's `CHANGELOG.md` and `LICENSE.md` never land there. | @@ -79,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 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 `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 and back with `traefik_update` (a real download, checksum check and swap) and asserts the version, an active unit and no leftovers. +- 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. diff --git a/roles/traefik/defaults/main.yml b/roles/traefik/defaults/main.yml index 03d2671..4c5cf94 100644 --- a/roles/traefik/defaults/main.yml +++ b/roles/traefik/defaults/main.yml @@ -9,6 +9,8 @@ traefik_version: "v3.7.19" traefik_arch: "amd64" traefik_os: "linux" +# Directory URL holding the release archive and its checksums file. +traefik_release_url: "https://github.com/traefik/traefik/releases/download/{{ traefik_version }}" traefik_archive_name: "traefik_{{ traefik_version }}_{{ traefik_os }}_{{ traefik_arch }}.tar.gz" traefik_local_archive: "/tmp/traefik.tar.gz" diff --git a/roles/traefik/meta/argument_specs.yml b/roles/traefik/meta/argument_specs.yml index 9e21bd8..654b4c6 100644 --- a/roles/traefik/meta/argument_specs.yml +++ b/roles/traefik/meta/argument_specs.yml @@ -63,6 +63,14 @@ argument_specs: default: linux description: - Operating system part of the release archive name. + traefik_release_url: + type: raw + description: + - >- + URL of the directory holding the release archive and C(traefik__checksums.txt), + without a trailing slash. The role default is the Jinja expression + C(https://github.com/traefik/traefik/releases/download/); point it at a mirror + for a host without access to github.com. traefik_archive_name: type: raw description: diff --git a/roles/traefik/molecule/default/molecule.yml b/roles/traefik/molecule/default/molecule.yml index 8288582..e6386a4 100644 --- a/roles/traefik/molecule/default/molecule.yml +++ b/roles/traefik/molecule/default/molecule.yml @@ -2,8 +2,9 @@ # Runs on the repository's own runner (label kamino-molecule), in the molecule-ubuntu2404 # (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 downloads Traefik releases from GitHub. No privileged mode: systemd needs a -# writable cgroup and the firewall tools need NET_ADMIN. +# 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 +# cgroup and the firewall tools need NET_ADMIN. driver: name: docker platforms: @@ -54,6 +55,9 @@ provisioner: traefik_cloudflare_email: molecule@example.test 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. + traefik_verify_other_version: v3.7.18 ufw_rules: - {rule: allow, port: 22, proto: tcp, comment: ssh} # TEST-NET-1 address: nothing answers, the value only has to render diff --git a/roles/traefik/molecule/default/prepare.yml b/roles/traefik/molecule/default/prepare.yml index 5c82815..fb16685 100644 --- a/roles/traefik/molecule/default/prepare.yml +++ b/roles/traefik/molecule/default/prepare.yml @@ -40,3 +40,55 @@ ProtectKernelTunables=no 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 +# still downloads the real role default from GitHub. +- name: Prepare the stand-in releases + hosts: all + gather_facts: false + vars_files: + - ../../defaults/main.yml + tasks: + - 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 binaries + ansible.builtin.copy: + dest: "/opt/molecule-download/{{ traefik_test_release }}/traefik" + mode: "0755" + content: | + #!/bin/sh + case "$1" in + 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 + 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 + 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 diff --git a/roles/traefik/molecule/default/tasks/update_and_check.yml b/roles/traefik/molecule/default/tasks/update_and_check.yml index ea20084..8753afc 100644 --- a/roles/traefik/molecule/default/tasks/update_and_check.yml +++ b/roles/traefik/molecule/default/tasks/update_and_check.yml @@ -5,6 +5,7 @@ vars: traefik_update: true traefik_version: "{{ traefik_verify_target }}" + traefik_release_url: "file:///opt/molecule-download/{{ traefik_verify_target }}" - name: Read the Traefik version after the update to {{ traefik_verify_target }} ansible.builtin.command: /usr/local/bin/traefik version diff --git a/roles/traefik/molecule/default/verify.yml b/roles/traefik/molecule/default/verify.yml index 51a001e..7b0c8f9 100644 --- a/roles/traefik/molecule/default/verify.yml +++ b/roles/traefik/molecule/default/verify.yml @@ -107,13 +107,40 @@ name: traefik register: traefik_unit - - name: Let the ACME failures against the dummy credentials play out - ansible.builtin.pause: - seconds: 15 + # The dummy credentials make the ACME request fail, logged as "Unable to obtain ACME certificate + # for domain(s)". The log keeps the lines of the process converge restarted, so only a line + # stamped (RFC 3339, first field) since the running process started counts. + - name: Wait until the running Traefik has logged the ACME failure + ansible.builtin.shell: + executable: /bin/bash + cmd: | + set -euo pipefail + started=$(systemctl show --timestamp=unix -P ExecMainStartTimestamp traefik) + if [[ ! $started =~ ^@[0-9]+$ ]]; then + echo "no start time for traefik: '${started}'" >&2 + exit 1 + fi + last=$(grep 'Unable to obtain ACME certificate' /etc/traefik/logs/traefik.log | tail -n 1 | cut -d ' ' -f 1) || true + # Fails closed: a missing line, an unparseable stamp or an older one all end in exit 1. + if [ -n "$last" ] && stamp=$(date -d "$last" +%s) && [ "$stamp" -ge "${started#@}" ]; then + exit 0 + fi + echo "no ACME failure logged since Traefik started at ${started} (last: ${last:-none})" >&2 + exit 1 + register: traefik_acme_failure + changed_when: false + until: traefik_acme_failure.rc == 0 + retries: 30 + delay: 2 - - name: Read the service state after the wait + - name: Read the service state after the ACME failure ansible.builtin.service_facts: + - name: Read the restart count after the ACME failure + ansible.builtin.systemd: + name: traefik + register: traefik_unit_after_acme + - name: The pinned version is installed ansible.builtin.assert: that: @@ -224,6 +251,8 @@ that: - ansible_facts.services['traefik.service'].state == 'running' - ansible_facts.services['traefik.service'].status == 'enabled' + # Restart=always would hide a crash on the ACME failure from the state above. + - traefik_unit_after_acme.status.NRestarts == '0' - traefik_unit.status.NoNewPrivileges == 'yes' - traefik_unit.status.MemoryDenyWriteExecute == 'yes' - "'cap_net_bind_service' in traefik_unit.status.AmbientCapabilities | lower" @@ -264,17 +293,15 @@ 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 real 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. After the idempotence step, -# because each run changes the binary, and before the remove path, which deletes it. -- name: Verify the update path with real Traefik releases +# 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 stand-in releases hosts: all gather_facts: false vars_files: - ../../defaults/main.yml - vars: - # Any published release other than the role default, with a checksum file. - traefik_verify_other_version: v3.7.18 tasks: - name: The other release differs from the role default ansible.builtin.assert: diff --git a/roles/traefik/tasks/binary/download.yml b/roles/traefik/tasks/binary/download.yml index 4854978..be382cc 100644 --- a/roles/traefik/tasks/binary/download.yml +++ b/roles/traefik/tasks/binary/download.yml @@ -12,7 +12,7 @@ # would otherwise be kept and then fail the checksum check. - name: Download Traefik archive ansible.builtin.get_url: - url: "https://github.com/traefik/traefik/releases/download/{{ traefik_version }}/{{ traefik_archive_name }}" + url: "{{ traefik_release_url }}/{{ traefik_archive_name }}" dest: "{{ traefik_local_archive }}" mode: "0644" force: true @@ -20,7 +20,7 @@ - name: Download Traefik checksums ansible.builtin.get_url: - url: "https://github.com/traefik/traefik/releases/download/{{ traefik_version }}/traefik_{{ traefik_version }}_checksums.txt" + url: "{{ traefik_release_url }}/traefik_{{ traefik_version }}_checksums.txt" dest: /tmp/traefik_checksums.txt mode: "0644" force: true