---

- include_tasks: ../functions/get_secret.yml
  with_items:
   - { path: /srv/shared/noreply_email_pass, length: -1 } 
   - { path: /srv/keycloak/keycloak_admin_pass,  length: 32 }
   - { path: /srv/keycloak/postgres_user_pass,  length: 24 }


- name: create folder struct for keycloak
  file:
    path: "{{ item }}"
    state: "directory"
  with_items:
    - /srv/keycloak/
    - /srv/keycloak/db/
    - /srv/keycloak/sync-group-active/
    - /srv/keycloak/themes/
    - /srv/keycloak/themes/keycloak/
    - /srv/keycloak/themes/keycloak/account/
    - /srv/keycloak/themes/keycloak/login/
    - /srv/keycloak/welcome-content/


- name: Konfig-Dateien erstellen
  template:
    src: "{{ item }}"
    dest: "/srv/keycloak/{{ item }}"
  with_items:
    - docker-compose.yml
    - sync-group-active/Dockerfile
    - sync-group-active/main.py
    - themes/keycloak/account/account.ftl
    - themes/keycloak/login/register.ftl
    - welcome-content/index.html
    - welcome-content/robots.txt
  register: config


- name: stop keycloak docker
  docker_compose:
    project_src: /srv/keycloak/
    state: absent
  when: config.changed


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