jugasit / jugasit.keycloak / 1.1.0 / module / clientscope Allows administration of Keycloak client_scopes via Keycloak API | "added in version" 1.0.0 of jugasit.keycloak" Authors: Gaëtan Daubresse (@Gaetan2907)jugasit.keycloak.clientscope (1.1.0) — module
Install with ansible-galaxy collection install jugasit.keycloak:==1.1.0
collections: - name: jugasit.keycloak version: 1.1.0
This module allows you to add, remove or modify Keycloak client_scopes via the Keycloak REST API. It requires access to the REST API via OpenID Connect; the user connecting and the client being used must have the requisite access rights. In a default Keycloak installation, admin-cli and an admin user would work, as would a separate client definition with the scope tailored to your needs and a user having the expected roles.
The names of module options are snake_cased versions of the camelCase ones found in the Keycloak API and its documentation at U(https://www.keycloak.org/docs-api/8.0/rest-api/index.html).
Attributes are multi-valued in the Keycloak API. All attributes are lists of individual values and will be returned that way by this module. You may pass single values for attributes when calling the module, and this will be translated into a list suitable for the API.
When updating a client_scope, where possible provide the client_scope ID to the module. This removes a lookup to the API to translate the name into the client_scope ID.
- name: Create a Keycloak client_scopes, authentication with credentials jugasit.keycloak.clientscope: name: my-new-kc-clientscope realm: MyCustomRealm state: present auth_client_id: admin-cli auth_keycloak_url: https://auth.example.com/auth auth_realm: master auth_username: USERNAME auth_password: PASSWORD delegate_to: localhost
- name: Create a Keycloak client_scopes, authentication with token jugasit.keycloak.clientscope: name: my-new-kc-clientscope realm: MyCustomRealm state: present auth_client_id: admin-cli auth_keycloak_url: https://auth.example.com/auth token: TOKEN delegate_to: localhost
- name: Delete a keycloak client_scopes jugasit.keycloak.clientscope: id: '9d59aa76-2755-48c6-b1af-beb70a82c3cd' state: absent realm: MyCustomRealm auth_client_id: admin-cli auth_keycloak_url: https://auth.example.com/auth auth_realm: master auth_username: USERNAME auth_password: PASSWORD delegate_to: localhost
- name: Delete a Keycloak client_scope based on name jugasit.keycloak.clientscope: name: my-clientscope-for-deletion state: absent auth_client_id: admin-cli auth_keycloak_url: https://auth.example.com/auth auth_realm: master auth_username: USERNAME auth_password: PASSWORD delegate_to: localhost
- name: Update the name of a Keycloak client_scope jugasit.keycloak.clientscope: id: '9d59aa76-2755-48c6-b1af-beb70a82c3cd' name: an-updated-kc-clientscope-name state: present auth_client_id: admin-cli auth_keycloak_url: https://auth.example.com/auth auth_realm: master auth_username: USERNAME auth_password: PASSWORD delegate_to: localhost
- name: Create a Keycloak client_scope with some custom attributes jugasit.keycloak.clientscope: auth_client_id: admin-cli auth_keycloak_url: https://auth.example.com/auth auth_realm: master auth_username: USERNAME auth_password: PASSWORD name: my-new_clientscope description: description-of-clientscope protocol: openid-connect protocol_mappers: - config: access.token.claim: true claim.name: "family_name" id.token.claim: true jsonType.label: String user.attribute: lastName userinfo.token.claim: true name: family name protocol: openid-connect protocolMapper: oidc-usermodel-property-mapper - config: attribute.name: Role attribute.nameformat: Basic single: false name: role list protocol: saml protocolMapper: saml-role-list-mapper attributes: attrib1: value1 attrib2: value2 attrib3: - with - numerous - individual - list - items delegate_to: localhost
id: description: - The unique identifier for this client_scope. - This parameter is not required for updating or deleting a client_scope but providing it will reduce the number of API calls required. type: str name: description: - Name of the client_scope. - This parameter is required only when creating or updating the client_scope. type: str realm: default: master description: - They Keycloak realm under which this client_scope resides. type: str state: choices: - present - absent default: present description: - State of the client_scope. - On C(present), the client_scope will be created if it does not yet exist, or updated with the parameters you provide. - On C(absent), the client_scope will be removed if it exists. type: str token: description: - Authentication token for Keycloak API. type: str version_added: 1.0.0 version_added_collection: jugasit.keycloak protocol: choices: - openid-connect - saml - wsfed description: - Type of client. type: str attributes: description: - A dict of key/value pairs to set as custom attributes for the client_scope. - Values may be single values (for example a string) or a list of strings. type: dict auth_realm: default: master description: - Keycloak realm name to authenticate to for API access. type: str http_agent: default: Ansible description: - Configures the HTTP User-Agent header. type: str version_added: 1.0.0 version_added_collection: jugasit.keycloak description: description: - Description for this client_scope. - This parameter is not required for updating or deleting a client_scope. type: str auth_password: description: - Password to authenticate for API access with. - If the value is not specified in the task, the value of environment variable C(KEYCLOAK_PASSWORD) or C(SSO_PASSWORD) will be used instead. type: str auth_username: description: - Username to authenticate for API access with. - If the value is not specified in the task, the value of environment variable C(KEYCLOAK_USERNAME) or C(SSO_USERNAME) will be used instead. type: str auth_client_id: default: admin-cli description: - OpenID Connect I(client_id) to authenticate to the API with. type: str validate_certs: default: true description: - Verify TLS certificates (do not disable this in production). type: bool protocol_mappers: aliases: - protocolMappers description: - A list of dicts defining protocol mappers for this client. - This is 'protocolMappers' in the Keycloak REST API. elements: dict suboptions: config: description: - Dict specifying the configuration options for the protocol mapper; the contents differ depending on the value of I(protocolMapper) and are not documented other than by the source of the mappers and its parent class(es). An example is given below. It is easiest to obtain valid config values by dumping an already-existing protocol mapper configuration through check-mode in the C(existing) return value. type: dict id: description: - Usually a UUID specifying the internal ID of this protocol mapper instance. type: str name: description: - The name of this protocol mapper. type: str protocol: choices: - openid-connect - saml - wsfed description: - This specifies for which protocol this protocol mapper. - is active. type: str protocolMapper: description: - 'The Keycloak-internal name of the type of this protocol-mapper. While an exhaustive list is impossible to provide since this may be extended through SPIs by the user of Keycloak, by default Keycloak as of 3.4 ships with at least:' - C(docker-v2-allow-all-mapper) - C(oidc-address-mapper) - C(oidc-full-name-mapper) - C(oidc-group-membership-mapper) - C(oidc-hardcoded-claim-mapper) - C(oidc-hardcoded-role-mapper) - C(oidc-role-name-mapper) - C(oidc-script-based-protocol-mapper) - C(oidc-sha256-pairwise-sub-mapper) - C(oidc-usermodel-attribute-mapper) - C(oidc-usermodel-client-role-mapper) - C(oidc-usermodel-property-mapper) - C(oidc-usermodel-realm-role-mapper) - C(oidc-usersessionmodel-note-mapper) - C(saml-group-membership-mapper) - C(saml-hardcode-attribute-mapper) - C(saml-hardcode-role-mapper) - C(saml-role-list-mapper) - C(saml-role-name-mapper) - C(saml-user-attribute-mapper) - C(saml-user-property-mapper) - C(saml-user-session-note-mapper) - An exhaustive list of available mappers on your installation can be obtained on the admin console by going to Server Info -> Providers and looking under 'protocol-mapper'. type: str type: list auth_keycloak_url: aliases: - url description: - URL to the Keycloak instance. - If the value is not specified in the task, the value of environment variable C(KEYCLOAK_URL) or C(SSO_URL) will be used instead. required: false type: str auth_client_secret: description: - Client Secret to use in conjunction with I(auth_client_id) (if required). type: str connection_timeout: default: 10 description: - Controls the HTTP connections timeout period (in seconds) to Keycloak API. type: int version_added: 1.0.0 version_added_collection: jugasit.keycloak
end_state: description: Representation of client scope after module execution (sample is truncated). returned: on success sample: adminUrl: http://www.example.com/admin_url attributes: request.object.signature.alg: RS256 type: dict existing: description: Representation of existing client scope (sample is truncated). returned: always sample: adminUrl: http://www.example.com/admin_url attributes: request.object.signature.alg: RS256 type: dict msg: description: Message as to what action was taken. returned: always sample: Client_scope testclientscope has been updated type: str proposed: description: Representation of proposed client scope. returned: always sample: clientId: test type: dict