--- # 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