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

- name: copy oidc.config.php
  template: 
    src: oidc.config.php.j2
    dest: "{{nextcloud_host_oidc_login_path}}"
    owner: 82 # User www-data in Nextcloud container
    group: 82 # User www-data in Nextcloud container
  when: applications[application_id].oidc.flavor == "oidc_login" 

- name: Remove OIDC configuration lines from config.php if present (container)
  command: >
    docker exec -u www-data {{ nextcloud_application_container_name }} sh -c "sed -i '/CONFIG_EXTRA = include.*oidc\.config\.php/d' /var/www/html/config/config.php && sed -i '/CONFIG = array_merge(\\$CONFIG, \\$CONFIG_EXTRA)/d' /var/www/html/config/config.php"
  when: applications[application_id].oidc.flavor == "sociallogin" and mode_cleanup | bool 

- name: "include role for {{application_id}} to recieve certs & do modification routines"
  include_role:
    name: nginx-https-get-cert-modify-all

- name: create nextcloud nginx proxy configuration file
  template: 
    src:  "proxy-nginx.conf.j2" 
    dest: "{{nginx.directories.http.servers}}{{domains[application_id]}}.conf"
  notify: restart nginx

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

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

- name: "Include OIDC-specific tasks with flavor {{applications[application_id].oidc.flavor}}"
  include_tasks: "{{applications[application_id].oidc.flavor}}.yml"
  when: applications[application_id].oidc.enabled | bool

- name: Include LDAP specific tasks
  include_tasks: ldap.yml
  when: applications[application_id].ldap.enabled | bool

- name: Include Config specific tasks
  include_tasks: config.yml

- name: De\Activate legacy login mask
  include_tasks: legacy_login_mask.yml