---
- name: "Authenticating with keycloak server"
  uri:
    url: "{{ keycloak_server_url }}/auth/realms/master/protocol/openid-connect/token"
    method: POST
    body_format: form-urlencoded
    body: 'username={{ keycloak_admin_username }}&password={{ keycloak_admin_password }}&client_id=admin-cli&grant_type=password'
  register: keycloak_authentication
  delegate_to: 127.0.0.1
  become: false
  retries: 5
  delay: 5

- name: "Saving access_token as variable (fact)"
  set_fact: 
    access_token: "{{ keycloak_authentication.json.access_token }}"

- name: "Printing access_token for keycloak server"
  debug:
    msg: "{{ access_token }}"
  delegate_to: 127.0.0.1
  become: false
  when:
   - debug