---

- name: "Setup realm for {{ inventory_hostname }}"
  include_role:
    name: keycloak
    tasks_from: _authenticate

- name: "Setup realm for {{ inventory_hostname }}"
  include_role:
    name: keycloak
    tasks_from: _configure_realm
  vars:
    current_realm_password_policy: ''

- name: "Create realm users"
  include_role:
    name: keycloak
    tasks_from: _create_realm_groups

- name: "Create realm users"
  include_role:
    name: keycloak
    tasks_from: _create_realm_users

- name: "Create realm admin"
  include_role:
    name: keycloak
    tasks_from: _create_realm_admin

- name: "Create user group mappings"
  include_role:
    name: keycloak
    tasks_from: _configure_user_groupmembership_crud
  vars:
    realm_name: '{{ current_realm_name }}'
    bearer_token: '{{ access_token }}'
    username: '{{ item.username }}'
    destination_group: '{{ item.destination_group }}'
  loop: "{{ current_user_groupmembership }}"
  loop_control:
    label: "{{ item.username }} >> {{ item.destination_group }}"
