---

### tags:

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

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

- name: "Deploy docker templates for {{ inventory_hostname }}"
  include_role:
    name: hetzner-ansible-sma-deploy
    tasks_from: templates
  vars:
    current_config: "_docker"
    current_base_path: "{{ service_base_path }}"
    current_destination: "{{ inventory_hostname }}"
    current_owner: "{{ docker_owner }}"
    current_group: "{{ docker_group }}"
    current_docker: "{{ webdav_docker }}"

- name: "Deploy service templates for webdav"
  include_role:
    name: hetzner-ansible-sma-deploy
    tasks_from: templates
  vars:
    current_config: "webdav"
    current_base_path: "{{ service_base_path }}"
    current_destination: "{{ inventory_hostname }}"
    current_owner: "{{ docker_owner }}"
    current_group: "{{ docker_group }}"

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