homelab/roles/traefik/tasks/main.yml

31 lines
983 B
YAML

- name: Set default Traefik options
set_fact:
traefik_defaults:
- "--providers.docker"
- "--providers.docker.exposedbydefault=false"
- name: Create Traefik network
docker_network:
name: traefik-net
- name: Start Traefik container
docker_container:
name: "{{ traefik_name }}"
image: traefik:{{ traefik_version }}
command: "{{ traefik_defaults + traefik_options }}"
state: started
restart_policy: always
ports: "{{ traefik_ports }}"
networks_cli_compatible: "false"
networks:
- name: "traefik-net"
labels:
traefik.http.routers.traefik.rule: "Host(`{{ traefik_domain }}`)"
traefik.http.middlewares.auth.basicauth.users: "{{ traefik_auth }}"
traefik.http.routers.traefik.middlewares: "auth@docker"
traefik.http.routers.traefik.service: "api@internal"
traefik.docker.network: "proxy_traefik-net"
traefik.enable: "true"
volumes:
- /var/run/docker.sock:/var/run/docker.sock