Création du conteneur Traefik.

This commit is contained in:
William 2022-03-09 12:06:45 +01:00
parent b3d82b8848
commit 1f4fe923fa
4 changed files with 83 additions and 1 deletions

View File

@ -7,4 +7,7 @@ ansible_python_interpreter=/usr/bin/python3
www_user=user
www_group=group
www_home=/home/user
traefik_dashboard=false
traefik_dashboard_host=traefik.example.com
traefik_log_level=ERROR
traefik_letsencrypt_email=admin@example.com

View File

@ -13,3 +13,4 @@
roles:
- wwwuser
- docker
- traefik

View File

@ -0,0 +1,54 @@
---
- name: create directory
file:
path: "{{ www_home }}/traefik"
state: directory
owner: "{{ www_user }}"
group: "{{ www_group }}"
- name: check if acme file exists
stat:
path: "{{ www_home }}/traefik/acme.json"
register: acme_file
- name: create acme file if does not exists
file:
path: "{{ www_home }}/traefik/acme.json"
state: touch
mode: 0600
owner: "{{ www_user }}"
group: "{{ www_group }}"
when: acme_file.stat.exists == False
- name: add config file
template:
src: traefik.yml.j2
dest: "{{ www_home }}/traefik/traefik.yml"
mode: 0600
owner: "{{ www_user }}"
group: "{{ www_group }}"
- name: create network
docker_network:
name: web
- name: create container
docker_container:
name: traefik
image: traefik:2.4
restart_policy: unless-stopped
recreate: true
networks:
- name: web
ports:
- "80:80"
- "443:443"
volumes:
- "{{ www_home }}/traefik/traefik.yml:/etc/traefik/traefik.yml"
- "{{ www_home }}/traefik/acme.json:/acme.json"
- /var/run/docker.sock:/var/run/docker.sock
labels:
traefik.enable: "true"
traefik.http.routers.dashboard.rule: Host(`{{ traefik_dashboard_host }}`)
traefik.http.routers.dashboard.entryPoints: http
traefik.http.routers.dashboard.service: api@internal

View File

@ -0,0 +1,24 @@
entryPoints:
http:
address: :80
https:
address: :443
log:
level: {{ traefik_log_level | default('ERROR') }}
api:
dashboard: {{ traefik_dashboard | default(false) }}
providers:
docker:
network: web
exposedByDefault: false
certificatesResolvers:
letsencrypt:
acme:
email: "{{ traefik_letsencrypt_email }}"
storage: "acme.json"
httpChallenge:
entryPoint: http