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
213 lines
7.1 KiB
YAML
213 lines
7.1 KiB
YAML
---
|
|
# Fail closed: an enabled dashboard without credentials would be an open admin UI.
|
|
# Before the first template, so a refused run changes no file.
|
|
- name: Refuse an enabled dashboard without basicAuth users
|
|
ansible.builtin.assert:
|
|
that:
|
|
- >-
|
|
not (traefik_dashboard_enabled | bool)
|
|
or (traefik_dashboard_basicauth_users | default([]) | length > 0
|
|
and traefik_dashboard_basicauth_users | map('string') | select('match', '^[^:\s]+:\S+$') | list | length
|
|
== traefik_dashboard_basicauth_users | length)
|
|
fail_msg: >-
|
|
traefik_dashboard_enabled is true but traefik_dashboard_basicauth_users is empty or holds an entry that is
|
|
not a 'user:hash' htpasswd line, which would deploy an unauthenticated Traefik dashboard. Set vaulted
|
|
htpasswd users, or leave the dashboard disabled (the default).
|
|
quiet: true
|
|
# health too: the dynamic.yml render below carries it, and a guard that a tag skips guards nothing.
|
|
tags: [traefik, configure, health]
|
|
|
|
- name: Render Traefik static configuration
|
|
become: true
|
|
ansible.builtin.template:
|
|
src: traefik.yml.j2
|
|
dest: "{{ traefik_config_dir }}/traefik.yml"
|
|
owner: "{{ traefik_user }}"
|
|
group: "{{ traefik_user }}"
|
|
mode: "0600"
|
|
backup: true
|
|
notify: Restart Traefik
|
|
tags: [traefik, configure]
|
|
|
|
- name: Fail if dashboard-auth collides with a user-defined dynamic middleware
|
|
ansible.builtin.assert:
|
|
that:
|
|
- "'dashboard-auth' not in (traefik_dynamic_middlewares | default({}, true))"
|
|
fail_msg: >-
|
|
traefik_dynamic_middlewares defines a 'dashboard-auth' key, which
|
|
collides with the middleware traefik_dashboard_basicauth_users
|
|
renders under the same name. Rename the dynamic middleware.
|
|
when: traefik_dashboard_basicauth_users | default([]) | length > 0
|
|
tags: [traefik, configure]
|
|
|
|
# no_log unconditionally: with dashboard basicAuth on, this file holds
|
|
# htpasswd hashes, and a --diff run prints the old file body too - so the
|
|
# run that disables auth would leak the removed hashes if no_log depended on
|
|
# the new value. Tradeoff: --diff never shows changes to dynamic.yml.
|
|
# No `backup: true`, same as traefik.env below: every backup would be
|
|
# another root-owned copy of the hashes. A `users | length == 0` condition
|
|
# is not enough, as the disabling run would back up the hash-bearing file.
|
|
- name: Render Traefik dynamic configuration
|
|
become: true
|
|
ansible.builtin.template:
|
|
src: dynamic.yml.j2
|
|
dest: "{{ traefik_dynamic_dir }}/dynamic.yml"
|
|
owner: "{{ traefik_user }}"
|
|
group: "{{ traefik_user }}"
|
|
mode: "0600"
|
|
backup: false
|
|
# no_log hides the result; diff: false keeps the rendered hashes out of --diff.
|
|
diff: false
|
|
no_log: true
|
|
notify: Restart Traefik
|
|
tags: [traefik, configure, health]
|
|
|
|
# Clean up copies left by the `backup: true` this task used to carry.
|
|
# Ansible names them <file>.<pid>.<timestamp>~.
|
|
- name: Find stale Traefik dynamic config backups
|
|
become: true
|
|
ansible.builtin.find:
|
|
paths: "{{ traefik_dynamic_dir }}"
|
|
patterns: "dynamic.yml.*~"
|
|
register: traefik_dynamic_backups
|
|
tags: [traefik, configure]
|
|
|
|
- name: Remove stale Traefik dynamic config backups
|
|
become: true
|
|
ansible.builtin.file:
|
|
path: "{{ traefik_stale_backup.path }}"
|
|
state: absent
|
|
loop: "{{ traefik_dynamic_backups.files }}"
|
|
loop_control:
|
|
loop_var: traefik_stale_backup
|
|
label: "{{ traefik_stale_backup.path }}"
|
|
tags: [traefik, configure]
|
|
|
|
# no_log: this file holds the Cloudflare API key, and without it a --diff
|
|
# run prints the old and new file bodies to the console (and CI logs).
|
|
# No `backup: true` either, unlike the config templates above: each backup
|
|
# is another root-owned copy of the key, and a rotated key would live on in
|
|
# them indefinitely.
|
|
# Notifies a restart because Traefik only reads the file at start - a
|
|
# rotated key would otherwise sit unused until an unrelated restart.
|
|
- name: Create environment file for Traefik secrets
|
|
become: true
|
|
ansible.builtin.copy:
|
|
dest: "{{ traefik_config_dir }}/traefik.env"
|
|
content: |
|
|
CF_API_EMAIL={{ traefik_cloudflare_email }}
|
|
CF_API_KEY={{ traefik_cloudflare_api_token }}
|
|
owner: root
|
|
group: root
|
|
mode: "0600"
|
|
no_log: true
|
|
diff: false
|
|
notify: Restart Traefik
|
|
tags: [traefik, configure]
|
|
|
|
# Clean up copies left by the `backup: true` this task used to carry.
|
|
# Ansible names them <file>.<pid>.<timestamp>~.
|
|
- name: Find stale Traefik secret env backups
|
|
become: true
|
|
ansible.builtin.find:
|
|
paths: "{{ traefik_config_dir }}"
|
|
patterns: "traefik.env.*~"
|
|
register: traefik_env_backups
|
|
tags: [traefik, configure]
|
|
|
|
- name: Remove stale Traefik secret env backups
|
|
become: true
|
|
ansible.builtin.file:
|
|
path: "{{ traefik_stale_backup.path }}"
|
|
state: absent
|
|
loop: "{{ traefik_env_backups.files }}"
|
|
loop_control:
|
|
loop_var: traefik_stale_backup
|
|
label: "{{ traefik_stale_backup.path }}"
|
|
tags: [traefik, configure]
|
|
|
|
- name: Rotate the Traefik logs
|
|
become: true
|
|
ansible.builtin.template:
|
|
src: logrotate.traefik.j2
|
|
dest: /etc/logrotate.d/traefik
|
|
owner: root
|
|
group: root
|
|
mode: "0644"
|
|
tags: [traefik, configure]
|
|
|
|
- name: Create systemd service file for Traefik
|
|
become: true
|
|
ansible.builtin.copy:
|
|
dest: "{{ traefik_service_unit }}"
|
|
content: |
|
|
[Unit]
|
|
Description=Traefik
|
|
After=network.target
|
|
|
|
[Service]
|
|
User={{ traefik_user }}
|
|
Group={{ traefik_user }}
|
|
EnvironmentFile={{ traefik_config_dir }}/traefik.env
|
|
ExecStart={{ traefik_bin_path }} --configFile={{ traefik_config_dir }}/traefik.yml
|
|
WorkingDirectory={{ traefik_config_dir }}
|
|
Restart=always
|
|
AmbientCapabilities=CAP_NET_BIND_SERVICE
|
|
NoNewPrivileges=true
|
|
ProtectSystem=full
|
|
ProtectHome=true
|
|
PrivateTmp=true
|
|
ReadWritePaths={{ traefik_config_dir }} {{ traefik_dynamic_dir }} {{ traefik_acme_file }} {{ traefik_config_dir }}/logs
|
|
PrivateDevices=true
|
|
ProtectKernelModules=true
|
|
ProtectKernelTunables=true
|
|
MemoryDenyWriteExecute=true
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
owner: root
|
|
group: root
|
|
mode: "0644"
|
|
notify:
|
|
- Reload Systemd
|
|
- Restart Traefik
|
|
tags: [traefik, configure]
|
|
|
|
- name: Reload systemd daemon
|
|
become: true
|
|
ansible.builtin.systemd:
|
|
daemon_reload: true
|
|
tags: [traefik, configure]
|
|
|
|
- name: Trigger UFW after installing Traefik
|
|
ansible.builtin.include_role:
|
|
name: mortis.kamino.ufw
|
|
tasks_from: service_rules
|
|
apply:
|
|
tags: [traefik, configure, ufw]
|
|
vars:
|
|
ufw_service_name: traefik
|
|
ufw_service_rules: "{{ traefik_ufw_service_rules }}"
|
|
tags: [traefik, configure, ufw]
|
|
|
|
- name: Enable and start Traefik service
|
|
become: true
|
|
ansible.builtin.systemd:
|
|
name: traefik
|
|
enabled: true
|
|
state: started
|
|
tags: [traefik, configure]
|
|
|
|
- name: Check Traefik service status
|
|
become: true
|
|
ansible.builtin.systemd:
|
|
name: traefik
|
|
register: traefik_service_status
|
|
tags: [traefik, configure, health]
|
|
|
|
- name: Fail if Traefik service is not running
|
|
ansible.builtin.fail:
|
|
msg: "Traefik service is not running"
|
|
when: traefik_service_status.status.ActiveState != "active"
|
|
tags: [traefik, configure, health]
|