---

### tags:
###   update_certs
###   update_config
###   update_deployment

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

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

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

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

- name: "Deploy certificate templates for {{ logstash_id }}"
  include_role:
    name: hetzner-ansible-sma-deploy
    tasks_from: templates
  vars:
    current_config: "elastic-certs/{{ stage }}-certs"
    current_base_path: "{{ service_base_path }}"
    current_destination: "{{ logstash_id }}/certs"
    current_owner: "{{ docker_owner }}"
    current_group: "{{ docker_group }}"
    cleanup_destination: "true"
  tags:
    - update_certs
    - update_config

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