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
88 lines
8.9 KiB
Markdown
88 lines
8.9 KiB
Markdown
# traefik
|
|
|
|
Installs the Traefik reverse proxy as a systemd-managed binary, renders its static and dynamic configuration with Cloudflare DNS-challenge certificates, opens its ports through the `mortis.kamino.ufw` role, and optionally updates or removes it (removal also deletes its ufw rules). Variables and their types are defined in [`meta/argument_specs.yml`](meta/argument_specs.yml), which is the source of truth.
|
|
|
|
## Supported platforms
|
|
|
|
Ubuntu 24.04 (noble), the image the molecule scenario runs on. The role uses `ansible.builtin.apt`, so Debian-family hosts only, and needs outbound access to github.com for the release archive and checksum file. Only `traefik_install_type: binary` exists.
|
|
|
|
## Requirements and run order
|
|
|
|
- Use it by its fully qualified name, `mortis.kamino.traefik`.
|
|
- Run the `system_baseline` and `ufw` roles of this Collection first. The configure tasks pass `traefik_ufw_service_rules` (ports 80 and 443 by default) to the `service_rules` entry point of `mortis.kamino.ufw`, owner `traefik`, which needs ufw installed and active and the SSH rule in place. See the README of `mortis.kamino.ufw`.
|
|
- Secrets: `traefik_cloudflare_email` and `traefik_cloudflare_api_token` have no role default and are required. Map them from vaulted variables in inventory; the role never holds the values itself.
|
|
- `traefik_domain` has no role default and must be set in inventory.
|
|
- Updates: the update path stages the verified binary and hands the swap to `mortis.kamino._binary_update`, an internal role of this Collection.
|
|
- Pin `traefik_version` in inventory to move Traefik independently of Collection releases; the role default changes only with a release.
|
|
|
|
## Role variables
|
|
|
|
| Variable | Default | Required | Description |
|
|
|---|---|---|---|
|
|
| `traefik_domain` | none | yes | Zone appended to the dashboard and app subdomains. |
|
|
| `traefik_update` | `false` | no | Run the update tasks when the installed version differs from `traefik_version`: download and verify into a staging directory before anything is stopped, then `mortis.kamino._binary_update` stops, backs up, swaps, restarts and checks the version, and rolls back on failure. |
|
|
| `traefik_remove` | `false` | no | Stop and disable the service, remove unit and binary, then delete the role's ufw rules (owner `traefik`, `ufw_service_state: absent`). The last remove task deletes the role's ufw rules, so ufw must be active on the host or that task fails. Prerequisites, install, configure and update are skipped. |
|
|
| `traefik_remove_data` | `false` | no | With `traefik_remove`, also delete `traefik_config_dir`. |
|
|
| `traefik_install_type` | `binary` | no | Task directory selector; only `binary` exists. |
|
|
| `traefik_version` | pinned in `defaults/main.yml` | no | Release tag to install. |
|
|
| `traefik_arch` | `amd64` | no | Archive architecture. |
|
|
| `traefik_os` | `linux` | no | Archive OS. |
|
|
| `traefik_archive_name` | `traefik_<version>_<os>_<arch>.tar.gz` | no | Archive file name (templated). |
|
|
| `traefik_local_archive` | `/tmp/traefik.tar.gz` | no | Download destination, removed after extraction. |
|
|
| `traefik_bin_path` | `/usr/local/bin/traefik` | no | Binary path used by the unit and version checks; only the `traefik` file of the archive is extracted into its directory, so the file name must stay `traefik`. Only the `traefik` file is extracted, so the archive's `CHANGELOG.md` and `LICENSE.md` never land there. |
|
|
| `traefik_config_dir` | `/etc/traefik` | no | Static config, `traefik.env` and logs directory. |
|
|
| `traefik_dynamic_dir` | `<traefik_config_dir>/dynamic` | no | File-provider directory. |
|
|
| `traefik_acme_file` | `<traefik_config_dir>/acme.json` | no | ACME storage, mode 0600. |
|
|
| `traefik_service_unit` | `/etc/systemd/system/traefik.service` | no | Systemd unit file path written (and removed on `traefik_remove`). |
|
|
| `traefik_dns_challenge_resolvers` | `[]` | no | `host:port` or `[ipv6]:port` resolvers for the ACME DNS-01 propagation check; empty omits the `resolvers` block. Set per environment. |
|
|
| `traefik_user` | `traefik` | no | System user and group running the service. |
|
|
| `traefik_log_rotate_frequency` | `daily` | no | How often logrotate rotates `<traefik_config_dir>/logs/*.log` (`/etc/logrotate.d/traefik`, `copytruncate`). |
|
|
| `traefik_log_rotate_count` | `14` | no | Rotated log files to keep. |
|
|
| `traefik_log_rotate_max_size` | `500M` | no | Size that rotates a log early when logrotate runs. |
|
|
| `traefik_dynamic_apps` | `[]` | no | Extra apps: `service_name`, `subdomain` (trailing dot), `server_url`, optional `pass_host_header`. |
|
|
| `traefik_dashboard_enabled` | `false` | no | Serve the dashboard. When `true`, `traefik_dashboard_basicauth_users` must be non-empty or the role fails. |
|
|
| `traefik_dashboard_subdomain` | `traefik.` | no | Dashboard host prefix. |
|
|
| `traefik_dashboard_basicauth_users` | `[]` | no | htpasswd lines for dashboard basicAuth (credentials, `no_log`); required when the dashboard is enabled, ignored otherwise. |
|
|
| `traefik_dynamic_middlewares` | `{}` | no | Extra middlewares; `dashboard-auth` is reserved. |
|
|
| `traefik_trusted_proxy_ips` | `127.0.0.1/32`, `::1/128` | no | CIDRs trusted for forwarded headers. |
|
|
| `traefik_cloudflare_email` | none | yes | Cloudflare e-mail (`no_log`, vaulted source). |
|
|
| `traefik_cloudflare_api_token` | none | yes | Cloudflare API key (`no_log`, vaulted source). |
|
|
| `traefik_headers` | HSTS and security headers, see defaults | no | `default-headers` middleware; overriding replaces the whole mapping. |
|
|
| `traefik_ufw_service_rules` | allow 80 and 443 | no | Rules passed to `ufw` `service_rules` (owner `traefik`). |
|
|
|
|
## Tags
|
|
|
|
`traefik`, `remove`, `install`, `configure` and `update` select their task files. `prereqs` tasks are also tagged `always`, so they run under any tag. The required-input assert (`traefik_domain` and the Cloudflare inputs) is tagged `always` and runs before the remove path, so `traefik_remove=true` also needs them defined.
|
|
|
|
- `ufw` and `binary` select nothing on their own: they sit only on tasks inside included files (`configure.yml`, `install.yml`) whose includes in `main.yml` do not carry them. The `ufw` include sets `apply: tags`, so the `service_rules` tasks also run under `--tags traefik` or `--tags configure`. The rule removal in `tasks/binary/remove.yml` also carries `ufw` and `remove`, but `main.yml` includes the remove path only under `traefik` and `remove`.
|
|
- `health` is not read-only: it re-renders `dynamic.yml` (which can notify `Restart Traefik`) and checks that the service is `active`.
|
|
|
|
## Example play
|
|
|
|
```yaml
|
|
- name: Install Traefik
|
|
hosts: proxy
|
|
roles:
|
|
- role: mortis.kamino.traefik
|
|
vars:
|
|
traefik_domain: example.com
|
|
traefik_cloudflare_email: [email protected]
|
|
traefik_cloudflare_api_token: "{{ vault_cloudflare_token }}"
|
|
traefik_dynamic_apps:
|
|
- {service_name: whoami, subdomain: "whoami.", server_url: "http://127.0.0.1:8081"}
|
|
```
|
|
|
|
Update or remove: pass `-e traefik_update=true`, or `-e "traefik_remove=true traefik_remove_data=true" --tags remove`.
|
|
|
|
## Notes
|
|
|
|
- The role is not a state selector. `main.yml` runs prerequisites and configure unless `traefik_remove` is true; install runs only when the binary is absent; update only when `traefik_update` is true; remove only when `traefik_remove` is true, and then every other task in `main.yml` is skipped.
|
|
- Download integrity: the archive SHA-256 must appear in the release's checksum file or the play fails.
|
|
- Secrets: `traefik.env` (mode 0600, root) and `dynamic.yml` are rendered with `no_log: true`, and no backups are kept, so `--diff` never shows them. `dynamic.yml` may hold dashboard htpasswd hashes.
|
|
- The unit sets `NoNewPrivileges`, `ProtectSystem=full`, `ProtectHome`, `PrivateTmp`, `PrivateDevices`, `ProtectKernelModules`, `ProtectKernelTunables`, `MemoryDenyWriteExecute` and `CAP_NET_BIND_SERVICE`. The molecule scenario disables the namespace-based sandboxing and the `User=` switch with a drop-in because its container is unprivileged, so that sandboxing is not covered by CI.
|
|
- The role fails early (assert at the top of `tasks/main.yml`, runs under any tag and before the `remove` include) when `traefik_dns_challenge_resolvers` is not a list of `host:port` (or `[ipv6]:port`) strings, when `traefik_bin_path` is not an absolute path ending in `traefik`, or when `traefik_config_dir` or `traefik_service_unit` is not absolute.
|
|
- The DNS-challenge resolvers are environment-specific, so the role default is empty, which omits the `resolvers` block.
|
|
- The play fails when the service is not `active` after start.
|
|
- Molecule's verify also updates to another release and back with `traefik_update` (a real download, checksum check and swap) and asserts the version, an active unit and no leftovers.
|
|
- Molecule's second play expects the failure message containing `unauthenticated Traefik dashboard` (the dashboard guard: enabled without valid `user:hash` users); its third play expects `collides with the middleware`, raised by the dashboard-auth collision assert, which runs whenever users are set, also with the dashboard off.
|