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
95 lines
3.8 KiB
YAML
95 lines
3.8 KiB
YAML
---
|
|
# systemd's sandboxing directives (ProtectSystem, PrivateTmp, PrivateDevices and
|
|
# the Protect* family) need a mount namespace, which needs CAP_SYS_ADMIN. The
|
|
# test container is unprivileged on purpose, so without this drop-in the unit
|
|
# fails with status 226/NAMESPACE. The drop-in resets only those directives;
|
|
# the user, capabilities, environment file and ExecStart under test are the
|
|
# role's own. The sandbox itself is therefore not covered by this scenario.
|
|
#
|
|
# User is reset too. The switch to User=traefik fails in the unprivileged container
|
|
# (exit 217/USER, "Failed to keep CAP_SYS_ADMIN"), so the unit runs as root here.
|
|
# The traefik user, the file ownership checks and the other unit settings are
|
|
# still asserted.
|
|
- name: Prepare
|
|
hosts: all
|
|
gather_facts: false
|
|
tasks:
|
|
# The image ships without apt lists, and --check does not refresh them, so the fresh-host
|
|
# check finds the packages the role installs.
|
|
- name: Refresh the apt cache
|
|
ansible.builtin.apt:
|
|
update_cache: true
|
|
|
|
- name: Create the unit drop-in directory
|
|
ansible.builtin.file:
|
|
path: /etc/systemd/system/traefik.service.d
|
|
state: directory
|
|
mode: "0755"
|
|
|
|
- name: Disable the namespace-based sandboxing for the unprivileged container
|
|
ansible.builtin.copy:
|
|
dest: /etc/systemd/system/traefik.service.d/molecule.conf
|
|
mode: "0644"
|
|
content: |
|
|
[Service]
|
|
ProtectSystem=no
|
|
ProtectHome=no
|
|
PrivateTmp=no
|
|
PrivateDevices=no
|
|
ProtectKernelModules=no
|
|
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
|