feat(traefik): add the traefik role
Moves the traefik role from the environment repository, the first wave 2 role and the first caller of the internal _binary_update role. Against the source: - The update path stages the downloaded, checksum-verified binary in a directory next to the live one and hands the stop, backup, swap, restart, version check and rollback to mortis.kamino._binary_update (include_role with apply tags, so --tags update reaches it). A download or checksum failure still leaves the running service untouched and says so; a failure in the swap keeps the rollback message of _binary_update. - Two small behaviour changes come with _binary_update: the backup is taken whenever a live binary exists (the source skipped it when the binary reported no version), and a failure before the stop no longer restarts the running service. - The legacy name guards (pre-rename variables of the environment) are dropped, as in the wave 1 roles, and the argument_specs and README no longer mention them. - Environment references are gone from comments, the README and the argument_specs: issue numbers, host names, inventory paths, playbooks and the role's own history. The Renovate comment on traefik_version is dropped, since this repository has no manager for it; the README and argument_specs recommend pinning the version in inventory. - meta namespace mortis; the scenario follows the Kamino conventions (header, test_sequence, no provisioner env) and calls the role by FQCN. - The scenario's verify gains a real version bump: down to another release (v3.7.18) and back to the role default with traefik_update, asserting the version, an active unit and no staging directory, backup or download left behind. Changelog fragment, README Roadmap and the CLAUDE.md role list updated. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
This commit is contained in:
1 parent
82de44dade
commit
589b71a312
23 files changed
+1624
-3
No files matched your search
@@ -0,0 +1,57 @@
|
||||
---
|
||||
# Role variables come from the inventory group_vars in molecule.yml, so every play
|
||||
# renders identical configuration (idempotence).
|
||||
# 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).
|
||||
- name: Converge
|
||||
hosts: all
|
||||
gather_facts: true
|
||||
roles:
|
||||
- role: mortis.kamino.ufw
|
||||
- role: mortis.kamino.traefik
|
||||
|
||||
- name: Refuse an enabled dashboard without basicAuth users
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Run the role with the dashboard on and no users
|
||||
block:
|
||||
- name: Include traefik
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.traefik
|
||||
vars:
|
||||
traefik_dashboard_enabled: true
|
||||
traefik_dashboard_basicauth_users: []
|
||||
- name: Unreachable when the guard works
|
||||
ansible.builtin.fail:
|
||||
msg: traefik accepted an enabled dashboard without users
|
||||
rescue:
|
||||
- name: The dashboard guard, not something else, stopped the play
|
||||
ansible.builtin.assert:
|
||||
that: "'unauthenticated Traefik dashboard' in ansible_failed_result.msg | default('')"
|
||||
quiet: true
|
||||
|
||||
- name: Refuse a dashboard-auth middleware collision
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Run the role with a colliding middleware
|
||||
block:
|
||||
- name: Include traefik
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.traefik
|
||||
vars:
|
||||
traefik_dashboard_basicauth_users:
|
||||
- "admin:$apr1$x$y"
|
||||
traefik_dynamic_middlewares:
|
||||
dashboard-auth:
|
||||
basicAuth: {users: []}
|
||||
- name: Unreachable when the check works
|
||||
ansible.builtin.fail:
|
||||
msg: traefik accepted a colliding dashboard-auth middleware
|
||||
rescue:
|
||||
- name: The collision check, not something else, stopped the play
|
||||
ansible.builtin.assert:
|
||||
that: "'collides with the middleware' in ansible_failed_result.msg | default('')"
|
||||
quiet: true
|
||||
@@ -0,0 +1,64 @@
|
||||
---
|
||||
# Runs on the repository's own runner (label kamino-molecule), in the molecule-ubuntu2404 image
|
||||
# (MOLECULE_IMAGE, the pin 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.
|
||||
driver:
|
||||
name: docker
|
||||
platforms:
|
||||
- name: traefik-instance
|
||||
image: ${MOLECULE_IMAGE}
|
||||
pre_build_image: true
|
||||
pull: true
|
||||
command: /sbin/init
|
||||
cgroupns_mode: host
|
||||
volumes:
|
||||
- /sys/fs/cgroup:/sys/fs/cgroup:rw
|
||||
tmpfs:
|
||||
- /run
|
||||
- /run/lock
|
||||
capabilities:
|
||||
- NET_ADMIN
|
||||
security_opts:
|
||||
- apparmor=unconfined
|
||||
provisioner:
|
||||
name: ansible
|
||||
# One source for every play in converge.yml. The role renders traefik.yml before
|
||||
# its dashboard guard and its dashboard-auth collision check, so a play that included it with other
|
||||
# values would re-render the file and break the idempotence step.
|
||||
inventory:
|
||||
group_vars:
|
||||
all:
|
||||
# Dummy credentials: Traefik reads them at start and only uses them when it
|
||||
# asks Cloudflare for a certificate.
|
||||
traefik_cloudflare_email: [email protected]
|
||||
traefik_cloudflare_api_token: molecule-not-a-token
|
||||
traefik_domain: example.test
|
||||
ufw_rules:
|
||||
- {rule: allow, port: 22, proto: tcp, comment: ssh}
|
||||
# TEST-NET-1 address: nothing answers, the value only has to render
|
||||
traefik_dns_challenge_resolvers:
|
||||
- "192.0.2.53:53"
|
||||
traefik_dynamic_apps:
|
||||
- service_name: whoami
|
||||
subdomain: "whoami."
|
||||
server_url: http://127.0.0.1:8081
|
||||
verifier:
|
||||
name: ansible
|
||||
scenario:
|
||||
# molecule's default sequence minus its first destroy: the workflow removes what a killed run
|
||||
# left before any scenario starts, so that destroy only waits out the
|
||||
# driver's 5 s poll on a container that is not there. After an aborted local run, run
|
||||
# `molecule destroy` yourself.
|
||||
test_sequence:
|
||||
- dependency
|
||||
- cleanup
|
||||
- syntax
|
||||
- create
|
||||
- prepare
|
||||
- converge
|
||||
- idempotence
|
||||
- side_effect
|
||||
- verify
|
||||
- cleanup
|
||||
- destroy
|
||||
@@ -0,0 +1,36 @@
|
||||
---
|
||||
# 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:
|
||||
- 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=
|
||||
@@ -0,0 +1,41 @@
|
||||
---
|
||||
- name: Run the role with the update path to {{ traefik_verify_target }}
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.traefik
|
||||
vars:
|
||||
traefik_update: true
|
||||
traefik_version: "{{ traefik_verify_target }}"
|
||||
|
||||
- name: Read the Traefik version after the update to {{ traefik_verify_target }}
|
||||
ansible.builtin.command: /usr/local/bin/traefik version
|
||||
register: traefik_verify_bumped
|
||||
changed_when: false
|
||||
|
||||
- name: Read the Traefik unit after the update to {{ traefik_verify_target }}
|
||||
ansible.builtin.systemd:
|
||||
name: traefik
|
||||
register: traefik_verify_bumped_unit
|
||||
|
||||
- name: Stat the update leftovers after the update to {{ traefik_verify_target }}
|
||||
ansible.builtin.stat:
|
||||
path: "{{ traefik_verify_bump_leftover }}"
|
||||
loop:
|
||||
- /usr/local/bin/.traefik-staging
|
||||
- /usr/local/bin/traefik.bak
|
||||
- /tmp/traefik.tar.gz
|
||||
- /tmp/traefik_checksums.txt
|
||||
loop_control:
|
||||
loop_var: traefik_verify_bump_leftover
|
||||
register: traefik_verify_bump_leftovers
|
||||
|
||||
- name: Traefik runs the new release and nothing is left behind ({{ traefik_verify_target }})
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- traefik_verify_target | regex_replace('^v', '') in traefik_verify_bumped.stdout
|
||||
- traefik_verify_bumped_unit.status.ActiveState == 'active'
|
||||
- traefik_verify_bump_leftovers.results | selectattr('stat.exists') | list | length == 0
|
||||
fail_msg: >-
|
||||
version output {{ traefik_verify_bumped.stdout }}, unit {{ traefik_verify_bumped_unit.status.ActiveState }},
|
||||
left behind {{ traefik_verify_bump_leftovers.results | selectattr('stat.exists')
|
||||
| map(attribute='traefik_verify_bump_leftover') | list }}
|
||||
quiet: true
|
||||
@@ -0,0 +1,309 @@
|
||||
---
|
||||
- name: Verify
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
vars_files:
|
||||
- ../../defaults/main.yml
|
||||
tasks:
|
||||
- name: Check the installed Traefik version
|
||||
ansible.builtin.command: /usr/local/bin/traefik version
|
||||
register: traefik_version_out
|
||||
changed_when: false
|
||||
|
||||
- name: Stat the secret-bearing files and the binary
|
||||
ansible.builtin.stat:
|
||||
path: "{{ traefik_verify_file }}"
|
||||
loop:
|
||||
- /etc/traefik/traefik.env
|
||||
- /etc/traefik/dynamic/dynamic.yml
|
||||
- /etc/traefik/traefik.yml
|
||||
- /usr/local/bin/traefik
|
||||
loop_control:
|
||||
loop_var: traefik_verify_file
|
||||
register: traefik_files
|
||||
|
||||
- name: Read the dynamic configuration
|
||||
ansible.builtin.slurp:
|
||||
src: /etc/traefik/dynamic/dynamic.yml
|
||||
register: traefik_dynamic
|
||||
|
||||
- name: List listening TCP sockets
|
||||
ansible.builtin.command: ss -ltnH
|
||||
register: traefik_sockets
|
||||
changed_when: false
|
||||
|
||||
- name: Ask the web entrypoint for its redirect
|
||||
ansible.builtin.uri:
|
||||
url: http://127.0.0.1:80/
|
||||
follow_redirects: none
|
||||
status_code: [301, 302, 307, 308]
|
||||
register: traefik_http
|
||||
retries: 5
|
||||
delay: 2
|
||||
until: traefik_http.status is defined and traefik_http.status in [301, 302, 307, 308]
|
||||
|
||||
- name: Read the ufw rules
|
||||
ansible.builtin.command: ufw status
|
||||
register: traefik_ufw
|
||||
changed_when: false
|
||||
|
||||
- name: Read the rules ufw has stored
|
||||
ansible.builtin.command: ufw show added
|
||||
register: traefik_ufw_added
|
||||
changed_when: false
|
||||
environment: {LC_ALL: C}
|
||||
|
||||
- name: Read the effective unit settings
|
||||
ansible.builtin.systemd:
|
||||
name: traefik
|
||||
register: traefik_unit
|
||||
|
||||
- name: Let the ACME failures against the dummy credentials play out
|
||||
ansible.builtin.pause:
|
||||
seconds: 15
|
||||
|
||||
- name: Read the service state after the wait
|
||||
ansible.builtin.service_facts:
|
||||
|
||||
- name: The pinned version is installed
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- traefik_version_out.stdout is search('(?m)^Version:')
|
||||
- traefik_version | regex_replace('^v', '') in traefik_version_out.stdout
|
||||
quiet: true
|
||||
|
||||
- name: Stat the archive leftovers
|
||||
ansible.builtin.stat:
|
||||
path: "{{ traefik_verify_leftover }}"
|
||||
loop:
|
||||
- /usr/local/bin/CHANGELOG.md
|
||||
- /usr/local/bin/LICENSE.md
|
||||
- /tmp/traefik.tar.gz
|
||||
- /tmp/traefik_checksums.txt
|
||||
loop_control:
|
||||
loop_var: traefik_verify_leftover
|
||||
register: traefik_leftovers
|
||||
|
||||
# Only the binary is extracted, and the archive and checksum file are removed.
|
||||
- name: The install left nothing but the binary behind
|
||||
ansible.builtin.assert:
|
||||
that: traefik_leftovers.results | selectattr('stat.exists') | list | length == 0
|
||||
fail_msg: >-
|
||||
Left behind: {{ traefik_leftovers.results | selectattr('stat.exists') | map(attribute='traefik_verify_leftover') | list }}
|
||||
quiet: true
|
||||
|
||||
- name: Secrets are root-only and the config belongs to the traefik user
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- (traefik_files.results | selectattr('traefik_verify_file', 'eq', '/etc/traefik/traefik.env') | first).stat.mode == '0600'
|
||||
- (traefik_files.results | selectattr('traefik_verify_file', 'eq', '/etc/traefik/traefik.env') | first).stat.pw_name == 'root'
|
||||
- (traefik_files.results | selectattr('traefik_verify_file', 'eq', '/etc/traefik/dynamic/dynamic.yml') | first).stat.mode == '0600'
|
||||
- (traefik_files.results | selectattr('traefik_verify_file', 'eq', '/etc/traefik/dynamic/dynamic.yml') | first).stat.pw_name == 'traefik'
|
||||
- (traefik_files.results | selectattr('traefik_verify_file', 'eq', '/etc/traefik/traefik.yml') | first).stat.mode == '0600'
|
||||
- (traefik_files.results | selectattr('traefik_verify_file', 'eq', '/usr/local/bin/traefik') | first).stat.mode == '0755'
|
||||
quiet: true
|
||||
|
||||
- name: Read the logrotate configuration
|
||||
ansible.builtin.slurp:
|
||||
src: /etc/logrotate.d/traefik
|
||||
register: traefik_logrotate
|
||||
|
||||
- name: Let logrotate parse its configuration (debug mode changes nothing)
|
||||
ansible.builtin.command: logrotate --debug /etc/logrotate.d/traefik
|
||||
register: traefik_logrotate_debug
|
||||
changed_when: false
|
||||
|
||||
- name: The Traefik logs are rotated by copying and truncating, not by signal
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- "'/etc/traefik/logs/*.log {' in traefik_logrotate.content | b64decode"
|
||||
- "'copytruncate' in traefik_logrotate.content | b64decode"
|
||||
- "'rotate 14' in traefik_logrotate.content | b64decode"
|
||||
- "'su traefik traefik' in traefik_logrotate.content | b64decode"
|
||||
- traefik_logrotate_debug.rc == 0
|
||||
quiet: true
|
||||
|
||||
- name: Read the static configuration
|
||||
ansible.builtin.slurp:
|
||||
src: /etc/traefik/traefik.yml
|
||||
register: traefik_static
|
||||
|
||||
- name: The ACME resolvers render when set and are absent when empty
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- "'resolvers:' in traefik_static_render"
|
||||
- "'- \"192.0.2.53:53\"' in traefik_static_render"
|
||||
- "'resolvers:' not in traefik_empty_render"
|
||||
- "'dnsChallenge:' in traefik_empty_render"
|
||||
quiet: true
|
||||
vars:
|
||||
traefik_static_render: "{{ traefik_static.content | b64decode }}"
|
||||
traefik_empty_render: "{{ lookup('ansible.builtin.template', playbook_dir ~ '/../../templates/traefik.yml.j2') }}"
|
||||
traefik_dns_challenge_resolvers: []
|
||||
traefik_cloudflare_email: [email protected]
|
||||
|
||||
- name: The dashboard is off by default and the extra app is still routed
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- "'Host(`traefik.example.test`)' not in traefik_dyn_render"
|
||||
- "'api@internal' not in traefik_dyn_render"
|
||||
- "'dashboard-auth' not in traefik_dyn_render"
|
||||
- "'Host(`whoami.example.test`)' in traefik_dyn_render"
|
||||
- "'http://127.0.0.1:8081' in traefik_dyn_render"
|
||||
- "'dashboard: false' in traefik_static.content | b64decode"
|
||||
quiet: true
|
||||
vars:
|
||||
traefik_dyn_render: "{{ traefik_dynamic.content | b64decode }}"
|
||||
|
||||
- name: An enabled dashboard renders behind basicAuth
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- "'dashboard: true' in traefik_on_static"
|
||||
- "'Host(`traefik.example.test`)' in traefik_on_dynamic"
|
||||
- "'api@internal' in traefik_on_dynamic"
|
||||
- "'dashboard-auth@file' in traefik_on_dynamic"
|
||||
- "'admin:hash' in traefik_on_dynamic"
|
||||
quiet: true
|
||||
vars:
|
||||
traefik_dashboard_enabled: true
|
||||
traefik_dashboard_basicauth_users: ["admin:hash"]
|
||||
traefik_on_static: "{{ lookup('ansible.builtin.template', playbook_dir ~ '/../../templates/traefik.yml.j2') }}"
|
||||
traefik_on_dynamic: "{{ lookup('ansible.builtin.template', playbook_dir ~ '/../../templates/dynamic.yml.j2') }}"
|
||||
|
||||
- name: The service stays running with the role's unit settings
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- ansible_facts.services['traefik.service'].state == 'running'
|
||||
- ansible_facts.services['traefik.service'].status == 'enabled'
|
||||
- traefik_unit.status.NoNewPrivileges == 'yes'
|
||||
- traefik_unit.status.MemoryDenyWriteExecute == 'yes'
|
||||
- "'cap_net_bind_service' in traefik_unit.status.AmbientCapabilities | lower"
|
||||
# the molecule drop-in took effect, so the unit was started without the sandbox
|
||||
- traefik_unit.status.ProtectSystem == 'no'
|
||||
quiet: true
|
||||
|
||||
- name: Traefik listens on 80 and 443 and redirects http to https
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- traefik_sockets.stdout is search(':80\s')
|
||||
- traefik_sockets.stdout is search(':443\s')
|
||||
- traefik_http.status in [301, 302, 307, 308]
|
||||
quiet: true
|
||||
|
||||
- name: Ufw opens 80 and 443 next to SSH
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- traefik_ufw.stdout is search('(?m)^22/tcp\s+ALLOW')
|
||||
- traefik_ufw.stdout is search('(?m)^80\s+ALLOW')
|
||||
- traefik_ufw.stdout is search('(?m)^443\s+ALLOW')
|
||||
quiet: true
|
||||
|
||||
- name: The traefik rules carry the traefik owner tag, in order
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- traefik_ufw_tagged | length == 2
|
||||
- 'traefik_ufw_tagged[0] is search("80 comment .ansible-ufw\[traefik:[0-9a-f]{10}\]: Traefik http")'
|
||||
- 'traefik_ufw_tagged[1] is search("443 comment .ansible-ufw\[traefik:[0-9a-f]{10}\]: Traefik https")'
|
||||
- traefik_ufw_tagged[0] is search('\[traefik:' ~ traefik_ufw_key_80 ~ '\]')
|
||||
- traefik_ufw_tagged[1] is search('\[traefik:' ~ traefik_ufw_key_443 ~ '\]')
|
||||
- traefik_ufw_key_80 == '56ae54fb00'
|
||||
- traefik_ufw_key_443 == '6d1cd18d60'
|
||||
quiet: true
|
||||
vars:
|
||||
# sha1 of rule|port|proto|from|to|interface|direction, first ten hex characters
|
||||
traefik_ufw_key_80: "{{ ('allow|80|||||in' | hash('sha1'))[:10] }}"
|
||||
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
|
||||
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:
|
||||
that: traefik_verify_other_version != traefik_version
|
||||
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
|
||||
ansible.builtin.include_tasks: tasks/update_and_check.yml
|
||||
loop:
|
||||
- "{{ traefik_verify_other_version }}"
|
||||
- "{{ traefik_version }}"
|
||||
loop_control:
|
||||
loop_var: traefik_verify_target
|
||||
|
||||
# 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).
|
||||
# Nothing runs after verify except molecule's own cleanup and destroy of the container.
|
||||
# Assumptions: the plays above left the two tagged traefik rules in place, ufw active and the
|
||||
# unit installed; traefik_remove_data stays false, so the configuration directory is not asserted.
|
||||
# With traefik_remove set, the role skips prereqs, install, configure and update, so a reinstall
|
||||
# or re-render would show as the binary or the unit coming back.
|
||||
- name: Verify the remove path
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
vars_files:
|
||||
- ../../defaults/main.yml
|
||||
tasks:
|
||||
- name: Seed a rule without an owner tag, which the removal must keep
|
||||
ansible.builtin.command: ufw allow 8123/tcp comment 'molecule manual rule'
|
||||
changed_when: true
|
||||
|
||||
- name: Read the rules ufw has stored before the removal
|
||||
ansible.builtin.command: ufw show added
|
||||
register: traefik_rm_before
|
||||
changed_when: false
|
||||
environment: {LC_ALL: C}
|
||||
|
||||
- name: The traefik rules exist before the removal
|
||||
ansible.builtin.assert:
|
||||
that: traefik_rm_before.stdout_lines | select('search', 'ansible-ufw\[traefik:') | list | length == 2
|
||||
quiet: true
|
||||
|
||||
- name: Run the role with the remove flag
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.traefik
|
||||
vars:
|
||||
traefik_remove: true
|
||||
|
||||
- name: Read the rules ufw has stored after the removal
|
||||
ansible.builtin.command: ufw show added
|
||||
register: traefik_rm_after
|
||||
changed_when: false
|
||||
environment: {LC_ALL: C}
|
||||
|
||||
- name: Stat the unit and the binary the removal deletes
|
||||
ansible.builtin.stat:
|
||||
path: "{{ traefik_rm_path }}"
|
||||
loop:
|
||||
- "{{ traefik_service_unit }}"
|
||||
- "{{ traefik_bin_path }}"
|
||||
loop_control:
|
||||
loop_var: traefik_rm_path
|
||||
register: traefik_rm_files
|
||||
|
||||
- name: Ask systemd whether the service is still active
|
||||
ansible.builtin.systemd:
|
||||
name: traefik
|
||||
register: traefik_rm_active
|
||||
failed_when: false
|
||||
|
||||
- name: Only the traefik rules are gone, and nothing was installed again
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- traefik_rm_after.stdout_lines | select('search', 'ansible-ufw\[traefik:') | list | length == 0
|
||||
- traefik_rm_after.stdout_lines | select('search', '(^|[ ])22/tcp') | list | length > 0
|
||||
- traefik_rm_after.stdout_lines | select('search', '8123/tcp') | list | length == 1
|
||||
- traefik_rm_files.results | map(attribute='stat') | map(attribute='exists') | select | list | length == 0
|
||||
# the module errors for a unit that no longer exists, which is also a pass
|
||||
- (traefik_rm_active.status | default({})).ActiveState | default('inactive') != 'active'
|
||||
quiet: true
|
||||
Reference in new issue
Block a user