---

- name: Create installation folder
  file: 
    path: "{{ install_dir }}"
    state: directory

- name: reate mongo and nginx folder if they don't exist
  file:
    path: "{{ install_dir }}/data/{{ item }}"
    state: directory
  loop: ["nginx", "mongo"]

- name: Check for encryption.env
  stat: 
    path: "{{ install_dir }}/encryption.env"
  register: encryption_exists



- name: Copy template file
  template: src={{ item.src }} dest={{ item.dest }}
  loop:
    - { src: 'docker-compose.j2', dest: '{{ install_dir }}/docker-compose.yml'}
    - { src: 'mongo-init.js.j2', dest: '{{ install_dir }}/data/mongo/init.js'}
    - { src: 'docker.env.j2', dest: '{{ install_dir }}/docker.env'}
  become: yes


- name: Copy encryption template file
  template: src="encryption.env.j2" dest="{{ install_dir }}/encryption.env"
  when: not encryption_exists.stat.exists

- set_fact:
    ssl_cmt: "{% if ssl_enable == 'false' %}#{% endif %}"

- name: Copy nginx template file
  template: src="nginx-app.conf.j2" dest="{{ install_dir }}/data/nginx/app.conf.template"
  become: yes

