Files
Kamino/roles/traefik/molecule/default/prepare.yml
T
Defame1297 7bc3cc6bdf
Build / build (pull_request) Successful in 1m16s
Lint / lint (pull_request) Successful in 5m47s
Molecule / molecule (pull_request) Successful in 8m58s
feat(traefik): skip a fresh apt refresh and trim the scenario's repeated work
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
2026-11-28 21:39:33 +00:00

94 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=
# 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 release
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
ansible.builtin.file:
path: "/opt/molecule-download/{{ traefik_test_release }}"
state: directory
mode: "0755"
# Answers `version` like Traefik and otherwise stays up like the service.
- name: Write the stand-in binary
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
- 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"
- 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"