---
- name: Create Keycloak data directories
  ansible.builtin.file:
    path: "{{ item }}"
    state: directory
    owner: root
    group: root
    mode: "0755"
  loop:
    - "{{ sso_data_dir }}"
  tags: sso

- name: Create Keycloak database directory (postgres UID 999)
  ansible.builtin.file:
    path: "{{ sso_data_dir }}/db"
    state: directory
    owner: "999"
    group: "999"
    mode: "0700"
  tags: sso

- name: Deploy Docker Compose file
  ansible.builtin.template:
    src: docker-compose.yml.j2
    dest: "{{ sso_data_dir }}/docker-compose.yml"
    owner: root
    group: root
    mode: "0644"
  notify: Restart sso
  tags: sso

- name: Start Keycloak
  community.docker.docker_compose_v2:
    project_src: "{{ sso_data_dir }}"
    state: present
    pull: missing
  tags: sso
