I try to start docker containers with traefik labels. To create a traefik router for a container you have to put some labels like this.
app_names:
- tower01
- tower02
docker_labels:
awx_web:
traefik.enable: "true"
traefik.http.routers.{{ app_name }}.entrypoints: "http"
traefik.http.routers.{{ app_name }}.rule: "Host(`{{ app_server_fqdn }}`)"
traefik.http.routers.{{ app_name }}.middlewares: "https-redirect@file"
traefik.http.routers.{{ app_name }}-sec.entrypoints: "https"
traefik.http.routers.{{ app_name }}-sec.rule: "Host(`{{ app_server_fqdn }}`)"
traefik.http.routers.{{ app_name }}-sec.tls: "true"
traefik.http.routers.{{ app_name }}-sec.tls.options: "myTLSOptions@file"
traefik.http.routers.{{ app_name }}-sec.tls.certresolver: "le"
traefik.http.routers.{{ app_name }}-sec.middlewares: "default-headers@file"
traefik.http.services.{{ app_name }}.loadbalancer.server.port: "8052"
com.centurylinklabs.watchtower.enable: "{{ autoupdate_container[loop_item] }}"
and use a task similar to this:
- name: "{{ app_name }} | create awx web container"
docker_container:
name: "{{ app_name }}-web"
hostname: "awxweb"
user: "root"
image: "ansible/awx_web:{{ docker_image[loop_item] | default('latest') }}"
env: "{{ docker_env[loop_item] | default(omit) }}"
networks: [ name: "{{ app_name }}" ]
purge_networks: true
volumes: "{{ docker_volumes[loop_item] | default(omit) }}"
restart_policy: "unless-stopped"
labels: "{{ docker_labels[loop_item] | default(omit) }}"
state: "{{ state | default('started') }}"
loop: "{{ app_names }}"
Of course the labels should be:
traefik.http.routers.tower01.entrypoints: "http"
traefik.http.routers.tower01.rule: "Host(`{{ app_server_fqdn }}`)"
traefik.http.routers.tower01.middlewares: "https-redirect@file"
traefik.http.routers.tower01-sec.entrypoints: "https"
traefik.http.routers.tower01-sec.rule: "Host(`{{ app_server_fqdn }}`)"
traefik.http.routers.tower01-sec.tls: "true"
traefik.http.routers.tower01-sec.tls.options: "myTLSOptions@file"
traefik.http.routers.tower01-sec.tls.certresolver: "le"
traefik.http.routers.tower01-sec.middlewares: "default-headers@file"
traefik.http.services.tower01.loadbalancer.server.port: "8052"
Nevertheless Ansible doesn't process the jinja variable in the key name.
Any idea?