---
- name: "include role for {{ application_id }} to receive certs & do modification routines"
  include_role:
    name: srv-web-7-6-composer

- name: create nextcloud proxy configuration file
  template: 
    src:  "nginx/host.conf.j2" 
    dest: "{{ nextcloud_host_nginx_path }}"
  notify: restart openresty

- name: "load docker and db for {{ application_id }}"
  include_role: 
    name: cmp-db-docker
  vars:
    docker_compose_flush_handlers: false

- name: "create {{ nextcloud_host_config_additives_directory }}"
  file:
    path: "{{ nextcloud_host_config_additives_directory }}"
    state: directory
    mode: "0755"

- name: "Create config files at {{ nextcloud_host_config_additives_directory }}"
  template:
    src:    "{{ item }}"
    dest:   "{{ nextcloud_host_config_additives_directory }}/{{ item | basename | regex_replace('\\.j2$', '') }}"
    owner:  "{{ nextcloud_docker_user_id }}"
    group:  "{{ nextcloud_docker_user_id }}"
  loop:     "{{ lookup('fileglob', role_path ~ '/templates/config/*.j2', wantlist=True) }}"
  # Not all type of changes take instantly place. Due to this reason a rebuild is required.
  notify: docker compose up

- name: create internal nextcloud nginx configuration
  template: 
    src:  "nginx/docker.conf.j2" 
    dest: "{{ docker_compose.directories.volumes }}nginx.conf"
  notify: restart nextcloud nginx service

- name: Setup config.php 
  include_tasks: 01_config.yml

- name: Flush all handlers immediately so that occ can be used
  meta: flush_handlers

- name: Load system configuration steps
  include_tasks: "{{ item }}"
  loop:
    - 02_add_missing_indices.yml
    - 03_admin.yml
    - 04_system_config.yml

- name: Setup Nextcloud Plugins
  include_tasks: 05_plugin.yml
  loop: "{{ applications | get_app_conf(application_id, 'plugins', True) | dict2items }}"
  loop_control:
    loop_var: plugin_item
  vars:
    plugin_key:   "{{ plugin_item.key }}"
    plugin_value: "{{ plugin_item.value }}"
  when: nextcloud_plugins_enabled


