---

### tags:

- name: "Check if traefik/docker-compose.yml exists"
  stat:
    path: '{{ service_base_path }}/traefik/docker-compose.yml'
  register: check_docker_compose_file

- name: "Stop traefik"
  community.docker.docker_compose:
    project_src: '{{ service_base_path }}/traefik'
    state: absent
  when: check_docker_compose_file.stat.exists

- name: "Deploy docker templates for traefik"
  include_role:
    name: sma_deploy
    tasks_from: templates
  vars:
    current_config: "_docker"
    current_base_path: "{{ service_base_path }}"
    current_destination: "traefik"
    current_owner: "{{ docker_owner }}"
    current_group: "{{ docker_group }}"
    current_docker: "{{ traefik_docker }}"

- name: "Deploy service templates for traefik"
  include_role:
    name: sma_deploy
    tasks_from: templates
  vars:
    current_config: "traefik"
    current_base_path: "{{ service_base_path }}"
    current_destination: "traefik"
    current_owner: "{{ docker_owner }}"
    current_group: "{{ docker_group }}"

- name: "Ensure acme.json exists"
  copy:
    content: ""
    dest: '{{ service_base_path }}/traefik/acme.json'
    force: no
    owner: "{{ docker_owner }}"
    group: "{{ docker_group }}"
    mode: '0600'

- name: "Update traefik"
  community.docker.docker_compose:
    project_src: '{{ service_base_path }}/traefik'
    state: present
    pull: yes
  tags:
    - update_deployment
