--- - name: Prepare the OAuth Request to RH-SSO (static params) set_fact: oauth_payload: "grant_type=password" - name: Prepare the OAuth Request to RH-SSO (urlencode dynamic params) set_fact: oauth_payload: '{{ oauth_payload ~ "&" ~ item.key ~ "=" ~ (item.value|urlencode) }}' with_dict: client_id: '{{ sso_default_client_id }}' username: '{{ sso_service_username }}' password: '{{ sso_service_password }}' - name: Authenticate to RH-SSO using the service account uri: url: 'https://{{ sso_route_name }}/auth/realms/{{ sso_realm }}/protocol/openid-connect/token' body: '{{ oauth_payload }}' method: POST validate_certs: no return_content: yes register: response changed_when: false - name: Extract the access_token set_fact: access_token: '{{ response.json |json_query("access_token") }}' - debug: msg="access_token = {{ access_token }}" - name: Create an Initial Access Token in RH-SSO uri: url: 'https://{{ sso_route_name }}/auth/admin/realms/{{ sso_realm }}/clients-initial-access' validate_certs: no method: POST body: '{{ sso_initial_access_token_request }}' body_format: json headers: Authorization: 'Bearer {{ access_token }}' register: response - name: Extract the Initial Access Token from the RH-SSO response set_fact: initial_access_token: '{{ response.json |json_query("token") }}' - debug: msg="initial_access_token = {{ initial_access_token }}" - name: Get the current Realm configuration uri: url: 'https://{{ sso_route_name }}/auth/admin/realms/{{ sso_realm }}' validate_certs: no headers: Authorization: 'Bearer {{ access_token }}' register: response - name: Change the Realm configuration to extend the token lifetimes (see variable sso_default_realm_settings) set_fact: realm_config: '{{ response.json |combine(sso_default_realm_settings) }}' - name: Update the Realm configuration uri: url: 'https://{{ sso_route_name }}/auth/admin/realms/{{ sso_realm }}' validate_certs: no headers: Authorization: 'Bearer {{ access_token }}' method: PUT body: "{{ realm_config }}" body_format: json status_code: 204 - include: "create-user.yml" with_items: '{{ sso_users_to_create }}' loop_control: loop_var: sso_demo_user - include: "create-client.yml" with_items: '{{ sso_clients_to_create }}' loop_control: loop_var: sso_demo_client