---
### tags:
###   update_config
###   update_deployment

- name: "Setup DNS configuration for <{{ pgadmin_id }}> to <{{ stage_server_ip }}>"
  include_role:
    name: hetzner-ansible-dns
  vars:
    record_data: "{{ stage_server_ip }}"
    record_name: "{{ pgadmin_id }}"

- name: "Check if <{{ pgadmin_id }}/docker-compose.yml> exists"
  stat:
    path: "{{ service_base_path }}/{{ pgadmin_id }}/docker-compose.yml"
  register: check_docker_compose_file
  tags:
    - update_config
    - update_deployment

- name: "Stop <{{ pgadmin_id }}>"
  community.docker.docker_compose:
    project_src: "{{ service_base_path }}/{{ pgadmin_id }}"
    state: absent
  when: check_docker_compose_file.stat.exists
  tags:
    - update_deployment

- name: "Deploy docker templates for <{{ pgadmin_id }}>"
  include_role:
    name: hetzner-ansible-sma-deploy
    tasks_from: templates
  vars:
    current_config: "_docker"
    current_base_path: "{{ service_base_path }}"
    current_destination: "{{ pgadmin_id }}"
    current_owner: "{{ docker_owner }}"
    current_group: "{{ docker_group }}"
    current_docker: "{{ pgadmin4_docker }}"
  tags:
    - update_config

- name: "Deploy service templates for <{{ pgadmin_id }}>"
  include_role:
    name: hetzner-ansible-sma-deploy
    tasks_from: templates
  vars:
    current_config: "mpmx"
    current_base_path: "{{ service_base_path }}"
    current_destination: "{{ pgadmin_id }}"
    current_owner: "{{ docker_owner }}"
    current_group: "{{ docker_group }}"
  tags:
    - update_config

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