---
- name: "include docker-central-database"
  include_role: 
    name: docker-central-database

- name: Set nginx_docker_reverse_proxy_extra_configuration based on applications.listmonk.public_api_activated
  set_fact:
    nginx_docker_reverse_proxy_extra_configuration: >-
      {% if not applications.listmonk.public_api_activated %}
      {{ lookup('file', '{{ role_path }}/files/deactivate-public-api.conf') }}
      {% else %}
      ""
      {% endif %}

- name: "include role nginx-domain-setup for {{application_id}}"
  include_role:
    name: nginx-domain-setup
  vars:
    domain: 	"{{ domains[application_id] }}"
    http_port: 	"{{ ports.localhost.http[application_id] }}"

- name: "copy docker-compose.yml and env file"
  include_tasks: copy-docker-compose-and-env.yml

- name: add config.toml
  template: 
    src:  "config.toml.j2" 
    dest: "{{docker_compose.directories.config}}config.toml"
  notify: docker compose project setup

- name: flush docker service
  meta: flush_handlers
  when: applications.listmonk.setup |bool 

- name: setup routine for listmonk
  command:
    cmd:   docker compose run -T --rm application sh -c "yes | ./listmonk --install"
    chdir: "{{docker_compose.directories.instance}}"
  when: applications.listmonk.setup |bool