community / community.general / 8.5.0 / module / keycloak_role Allows administration of Keycloak roles via Keycloak API | "added in version" 3.4.0 of community.general" Authors: Laurent Paumier (@laurpaum)community.general.keycloak_role (8.5.0) — module
Install with ansible-galaxy collection install community.general:==8.5.0
collections: - name: community.general version: 8.5.0
This module allows you to add, remove or modify Keycloak roles 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.
- name: Create a Keycloak realm role, authentication with credentials community.general.keycloak_role: name: my-new-kc-role 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 realm role, authentication with token community.general.keycloak_role: name: my-new-kc-role realm: MyCustomRealm state: present auth_client_id: admin-cli auth_keycloak_url: https://auth.example.com/auth token: TOKEN delegate_to: localhost
- name: Create a Keycloak client role community.general.keycloak_role: name: my-new-kc-role realm: MyCustomRealm client_id: MyClient 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: Delete a Keycloak role community.general.keycloak_role: name: my-role-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: Create a keycloak role with some custom attributes community.general.keycloak_role: 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-role attributes: attrib1: value1 attrib2: value2 attrib3: - with - numerous - individual - list - items delegate_to: localhost
name: description: - Name of the role. - This parameter is required. required: true type: str realm: default: master description: - The Keycloak realm under which this role resides. type: str state: choices: - present - absent default: present description: - State of the role. - On V(present), the role will be created if it does not yet exist, or updated with the parameters you provide. - On V(absent), the role will be removed if it exists. type: str token: description: - Authentication token for Keycloak API. type: str version_added: 3.0.0 version_added_collection: community.general client_id: description: - If the role is a client role, the client id under which it resides. - If this parameter is absent, the role is considered a realm role. type: str composite: default: false description: - If V(true), the role is a composition of other realm and/or client role. type: bool version_added: 7.1.0 version_added_collection: community.general attributes: description: - A dict of key/value pairs to set as custom attributes for the role. - Values may be single values (e.g. a string) or a list of strings. type: dict auth_realm: description: - Keycloak realm name to authenticate to for API access. type: str composites: default: [] description: - List of roles to include to the composite realm role. - If the composite role is a client role, the C(clientId) (not ID of the client) must be specified. elements: dict suboptions: client_id: aliases: - clientId description: - Client ID if the role is a client role. Do not include this option for a REALM role. - Use the client ID you can see in the Keycloak console, not the technical ID of the client. required: false type: str name: description: - Name of the role. This can be the name of a REALM role or a client role. required: true type: str state: choices: - present - absent default: present description: - Create the composite if present, remove it if absent. type: str type: list version_added: 7.1.0 version_added_collection: community.general http_agent: default: Ansible description: - Configures the HTTP User-Agent header. type: str version_added: 5.4.0 version_added_collection: community.general description: description: - The role description. type: str auth_password: aliases: - password description: - Password to authenticate for API access with. type: str auth_username: aliases: - username description: - Username to authenticate for API access with. type: str auth_client_id: default: admin-cli description: - OpenID Connect C(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 auth_keycloak_url: aliases: - url description: - URL to the Keycloak instance. required: true type: str auth_client_secret: description: - Client Secret to use in conjunction with O(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: 4.5.0 version_added_collection: community.general
end_state: description: Representation of role after module execution (sample is truncated). returned: on success sample: attributes: {} clientRole: true composite: false containerId: 9f03eb61-a826-4771-a9fd-930e06d2d36a description: My updated client test role id: 561703dd-0f38-45ff-9a5a-0c978f794547 name: myrole type: dict existing: description: Representation of existing role. returned: always sample: attributes: {} clientRole: true composite: false containerId: 9f03eb61-a826-4771-a9fd-930e06d2d36a description: My client test role id: 561703dd-0f38-45ff-9a5a-0c978f794547 name: myrole type: dict msg: description: Message as to what action was taken. returned: always sample: Role myrole has been updated type: str proposed: description: Representation of proposed role. returned: always sample: description: My updated test description type: dict