---
- name: "Include docker-central-database"
  include_role: 
    name: docker-central-database
  
- name: "Include role nginx-domain-setup for {{ application_id }}"
  include_role:
    name: nginx-domain-setup
  loop: "{{ domains.wordpress }}"
  loop_control:
    loop_var: domain
  vars:
    nginx_docker_reverse_proxy_extra_configuration: "client_max_body_size {{ wordpress_max_upload_size }};"
    http_port: "{{ ports.localhost.http[application_id] }}"

- name: "Transfering upload.ini to {{ docker_compose.directories.instance }}"
  template:
    src: upload.ini.j2
    dest: "{{ docker_compose.directories.instance }}upload.ini"
  notify: docker compose project build and setup

- name: "Transfering msmtprc to {{ host_msmtp_conf }}"
  template:
    src: "{{ playbook_dir }}/roles/msmtp/templates/msmtprc.conf.j2"
    dest: "{{ host_msmtp_conf }}"
  notify: docker compose project build and setup

- include_tasks: "{{ playbook_dir }}/roles/docker-compose/tasks/create-files.yml"

- name: "Install wordpress"
  include_tasks: install.yml

- name: "Install and activate WordPress plugins from application config"
  block:
    - name: "Iterate through WordPress plugins"
      include_tasks: plugin.yml
      loop: "{{ applications[application_id].plugins | dict2items }}"
      loop_control:
        label: "{{ item.key }}"
      vars:
        plugin_name: "{{ item.key }}"
        plugin_enabled: "{{ item.value.enabled | bool }}"
        plugin_task_path: "{{ role_path }}/tasks/plugins/{{ plugin_name }}/install.yml"
      when: plugin_enabled
