Traefik Ansible role
https://doc.traefik.io/traefik/
- Jinja 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| .forgejo/workflows | ||
| defaults | ||
| meta | ||
| tasks | ||
| templates | ||
| CHANGELOG.md | ||
| LICENSE | ||
| README.md | ||
Traefik
Deploys a Traefik reverse proxy via Docker Compose with automatic TLS via Let's Encrypt and an optional admin dashboard.
Requirements
- Docker
community.dockerAnsible collection (>=5.2.0)
Variables
| Variable | Default | Description |
|---|---|---|
traefik_instance |
traefik |
Unique instance name. Used as Compose project name and container name. |
traefik_version |
v3.7.19 |
Traefik image tag. |
traefik_docker_path |
/docker/traefik |
Host path for Compose file, config, certs, and dynamic config. |
traefik_ports |
["80:80", "443:443"] |
List of host port mappings to expose. |
traefik_acme_email |
~ |
Required. Email address for Let's Encrypt certificate registration. |
traefik_domain |
~ |
Domain for the Traefik dashboard. When set, enables the dashboard with basic auth. |
traefik_user |
admin |
Dashboard basic-auth username. Used when traefik_domain is set. |
traefik_password |
~ |
Dashboard basic-auth password (or traefik_password_hash) when traefik_domain is set. New salt each run, so the container is recreated every time. |
traefik_password_hash |
~ |
Precomputed bcrypt hash (htpasswd -nbB), used instead of traefik_password. |
traefik_hetzner_token |
~ |
Hetzner API token. When set, switches ACME from HTTP challenge to Hetzner DNS challenge. |
traefik_dns_delay |
30 |
Seconds before the DNS-01 record is checked. |
traefik_dns_resolvers |
["1.1.1.1:53", "1.0.0.1:53"] |
DNS servers the DNS-01 check uses. Empty list = the container's resolver. |
traefik_container_dns |
[] |
dns: servers of the Traefik container. |
traefik_loglevel |
ERROR |
Log level. One of: DEBUG, INFO, WARN, ERROR, FATAL, PANIC. |
traefik_entrypoints |
HTTP→HTTPS redirect | Raw TOML block injected into [entryPoints]. Override to customize entry points. |
traefik_custom_config |
~ |
Raw TOML appended verbatim to the end of traefik.toml. |
traefik_uninstall |
false |
Stops and removes containers and the compose directory. |
Usage
Minimal setup:
traefik_acme_email: "admin@example.com"
With dashboard:
traefik_acme_email: "admin@example.com"
traefik_domain: "traefik.example.com"
traefik_password: "supersecret"
With Hetzner DNS challenge (required for wildcard certs or servers not reachable on port 80):
traefik_acme_email: "admin@example.com"
traefik_hetzner_token: "your-hetzner-api-token"
Uninstall
To stop and remove all containers and the compose directory:
traefik_uninstall: true
Notes
- Traefik creates a Docker bridge network named
traefik_web. Other containers that should be proxied must join this network and set thetraefik.enable=truelabel. - Dynamic configuration files placed in
{{ traefik_docker_path }}/dynamicare watched and applied without restart. - TLS is hardened to 1.2+ with a restricted cipher suite applied globally.
- Containers are not proxied by default — each must opt in with
traefik.enable=true.