---
- name: "include docker-compose role"
  include_role: 
    name: docker-compose

- 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: Create {{domains[application_id]}}.conf if LDAP is exposed to internet
  template: 
    src:  "nginx.stream.conf.j2" 
    dest: "{{nginx.directories.streams}}{{domains[application_id]}}.conf"
  notify: restart nginx
  when: applications.ldap.openldap.network.public | bool

- name: Remove {{domains[application_id]}}.conf if LDAP is not exposed to internet
  file:
    path: "{{ nginx.directories.streams }}{{ domains[application_id] }}.conf"
    state: absent
  when: not applications.ldap.openldap.network.public | bool

- name: create docker network for LDAP, so that other applications can access it
  docker_network:
    name: central_ldap
    state: present
    ipam_config:
      - subnet: "{{ networks.local.central_ldap.subnet }}"

- name: "create {{docker_compose.directories.env}}phpldapadmin.env"
  template: 
    src:  "phpldapadmin.env.j2" 
    dest: "{{docker_compose.directories.env}}phpldapadmin.env"
    mode: '770'
    force: yes
  notify: docker compose project setup
  when: applications.ldap.webinterface == 'phpldapadmin'
  
- name: "create {{docker_compose.directories.env}}lam.env"
  template: 
    src:  "lam.env.j2" 
    dest: "{{docker_compose.directories.env}}lam.env"
    mode: '770'
    force: yes
  notify: docker compose project setup
  when: applications.ldap.webinterface == 'lam'

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

- name: "create directory {{ldif_host_path}}{{item}}"
  file:
    path: "{{ldif_host_path}}{{item}}"
    state: directory
    mode: 0755
  loop: "{{ldif_types}}"

- name: "Process all LDIF types"
  include_tasks: create_ldif_files.yml
  loop: "{{ ldif_types }}"
  loop_control:
    loop_var: folder

- name: Force LDIF files import
  command: /bin/true
  notify: Import LDIF files
  when: applications.ldap.force_import | bool