---

- include_tasks: ../functions/get_secret.yml
  with_items:
   - { path: /srv/hackmd/mysql_root_pass,  length: 24 }
   - { path: /srv/hackmd/mysql_user_pass,  length: 12 }
   - { path: /srv/hackmd/hackmd_session_secret,  length: 32 }
   - { path: /srv/ldap/secret/ldap_readonly_pass,  length: -1 }


- name: create folder struct for hackmd
  file:
    path: "{{ item }}"
    state: "directory"
  with_items:
    - /srv/hackmd/
    - /srv/hackmd/db/


- name: Konfig-Dateien erstellen
  template:
    src: "{{ item }}"
    dest: "/srv/hackmd/{{ item }}"
  with_items:
    - docker-compose.yml
    - mysql-utf8.cnf
  register: configs

- name: stop hackmd docker
  docker_compose:
    project_src: /srv/hackmd
    state: absent
  when: configs.changed

- name: start hackmd docker
  docker_compose:
    project_src: /srv/hackmd/
    state: present
