| 1 |
--- |
| 2 |
# Copyright (c) Ansible Project |
| 3 |
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 4 |
# SPDX-License-Identifier: GPL-3.0-or-later |
| 5 |
- name: Wait for Keycloak |
| 6 |
uri: |
| 7 |
url: "{{ url }}/admin/" |
| 8 |
status_code: 200 |
| 9 |
validate_certs: false |
| 10 |
register: result |
| 11 |
until: result.status == 200 |
| 12 |
retries: 10 |
| 13 |
delay: 10 |
| 14 |
|
| 15 |
- name: Delete realm if exists |
| 16 |
community.general.keycloak_realm: |
| 17 |
auth_keycloak_url: "{{ url }}" |
| 18 |
auth_realm: "{{ admin_realm }}" |
| 19 |
auth_username: "{{ admin_user }}" |
| 20 |
auth_password: "{{ admin_password }}" |
| 21 |
realm: "{{ realm }}" |
| 22 |
state: absent |
| 23 |
|
| 24 |
- name: Create realm |
| 25 |
community.general.keycloak_realm: |
| 26 |
auth_keycloak_url: "{{ url }}" |
| 27 |
auth_realm: "{{ admin_realm }}" |
| 28 |
auth_username: "{{ admin_user }}" |
| 29 |
auth_password: "{{ admin_password }}" |
| 30 |
id: "{{ realm }}" |
| 31 |
realm: "{{ realm }}" |
| 32 |
state: present |
| 33 |
|
| 34 |
- name: Retrive ldap info when absent |
| 35 |
community.general.keycloak_component_info: |
| 36 |
auth_keycloak_url: "{{ url }}" |
| 37 |
auth_realm: "{{ admin_realm }}" |
| 38 |
auth_username: "{{ admin_user }}" |
| 39 |
auth_password: "{{ admin_password }}" |
| 40 |
name: "{{ federation }}" |
| 41 |
provider_type: "org.keycloak.storage.UserStorageProvider" |
| 42 |
realm: "{{ realm }}" |
| 43 |
register: result |
| 44 |
|
| 45 |
- name: Assert ldap is missing |
| 46 |
assert: |
| 47 |
that: |
| 48 |
- result is not changed |
| 49 |
- result.components | length == 0 |
| 50 |
|
| 51 |
- name: Create new user federation |
| 52 |
community.general.keycloak_user_federation: |
| 53 |
auth_keycloak_url: "{{ url }}" |
| 54 |
auth_realm: "{{ admin_realm }}" |
| 55 |
auth_username: "{{ admin_user }}" |
| 56 |
auth_password: "{{ admin_password }}" |
| 57 |
realm: "{{ realm }}" |
| 58 |
name: "{{ federation }}" |
| 59 |
state: present |
| 60 |
provider_id: ldap |
| 61 |
provider_type: org.keycloak.storage.UserStorageProvider |
| 62 |
config: |
| 63 |
enabled: true |
| 64 |
priority: 0 |
| 65 |
fullSyncPeriod: -1 |
| 66 |
changedSyncPeriod: -1 |
| 67 |
cachePolicy: DEFAULT |
| 68 |
batchSizeForSync: 1000 |
| 69 |
editMode: READ_ONLY |
| 70 |
importEnabled: true |
| 71 |
syncRegistrations: false |
| 72 |
vendor: other |
| 73 |
usernameLDAPAttribute: uid |
| 74 |
rdnLDAPAttribute: uid |
| 75 |
uuidLDAPAttribute: entryUUID |
| 76 |
userObjectClasses: "inetOrgPerson, organizationalPerson" |
| 77 |
connectionUrl: "ldap://ldap.example.com" |
| 78 |
usersDn: "ou=Users,dc=example,dc=com" |
| 79 |
authType: simple |
| 80 |
bindDn: cn=directory reader |
| 81 |
bindCredential: secret |
| 82 |
searchScope: 1 |
| 83 |
validatePasswordPolicy: false |
| 84 |
trustEmail: false |
| 85 |
useTruststoreSpi: "ldapsOnly" |
| 86 |
connectionPooling: true |
| 87 |
pagination: true |
| 88 |
allowKerberosAuthentication: false |
| 89 |
useKerberosForPasswordAuthentication: false |
| 90 |
debug: false |
| 91 |
|
| 92 |
- name: Retrive ldap info |
| 93 |
community.general.keycloak_component_info: |
| 94 |
auth_keycloak_url: "{{ url }}" |
| 95 |
auth_realm: "{{ admin_realm }}" |
| 96 |
auth_username: "{{ admin_user }}" |
| 97 |
auth_password: "{{ admin_password }}" |
| 98 |
name: "{{ federation }}" |
| 99 |
provider_type: "org.keycloak.storage.UserStorageProvider" |
| 100 |
realm: "{{ realm }}" |
| 101 |
register: result |
| 102 |
|
| 103 |
- name: Assert ldap exists |
| 104 |
assert: |
| 105 |
that: |
| 106 |
- result is not changed |
| 107 |
- result.components | length == 1 |
| 108 |
- result.components[0].name == federation |
| 109 |
|
| 110 |
- name: Save ldap id |
| 111 |
set_fact: |
| 112 |
myLdapId: "{{ result.components[0].id }}" |
| 113 |
|
| 114 |
- name: Retrive ldap subcomponents info |
| 115 |
community.general.keycloak_component_info: |
| 116 |
auth_keycloak_url: "{{ url }}" |
| 117 |
auth_realm: "{{ admin_realm }}" |
| 118 |
auth_username: "{{ admin_user }}" |
| 119 |
auth_password: "{{ admin_password }}" |
| 120 |
realm: "{{ realm }}" |
| 121 |
parent_id: "{{ myLdapId }}" |
| 122 |
register: result |
| 123 |
|
| 124 |
- name: Assert components exists |
| 125 |
assert: |
| 126 |
that: |
| 127 |
- result is not changed |
| 128 |
- result.components | length > 0 |
| 129 |
|
| 130 |
- name: Retrive ldap subcomponents filter by name |
| 131 |
community.general.keycloak_component_info: |
| 132 |
auth_keycloak_url: "{{ url }}" |
| 133 |
auth_realm: "{{ admin_realm }}" |
| 134 |
auth_username: "{{ admin_user }}" |
| 135 |
auth_password: "{{ admin_password }}" |
| 136 |
realm: "{{ realm }}" |
| 137 |
parent_id: "{{ myLdapId }}" |
| 138 |
name: "email" |
| 139 |
register: result |
| 140 |
|
| 141 |
- name: Assert sub component with name "email" exists |
| 142 |
assert: |
| 143 |
that: |
| 144 |
- result is not changed |
| 145 |
- result.components | length == 1 |
| 146 |
- result.components[0].name == "email" |
| 147 |
|
| 148 |
- name: Retrive ldap subcomponents filter by type |
| 149 |
community.general.keycloak_component_info: |
| 150 |
auth_keycloak_url: "{{ url }}" |
| 151 |
auth_realm: "{{ admin_realm }}" |
| 152 |
auth_username: "{{ admin_user }}" |
| 153 |
auth_password: "{{ admin_password }}" |
| 154 |
realm: "{{ realm }}" |
| 155 |
parent_id: "{{ myLdapId }}" |
| 156 |
provider_type: "org.keycloak.storage.ldap.mappers.LDAPStorageMapper" |
| 157 |
register: result |
| 158 |
|
| 159 |
- name: Assert ldap sub components filter by type |
| 160 |
assert: |
| 161 |
that: |
| 162 |
- result is not changed |
| 163 |
- result.components | length > 0 |
| 164 |
- result.components[0].providerType == "org.keycloak.storage.ldap.mappers.LDAPStorageMapper" |
| 165 |
|
| 166 |
- name: Retrive key info when absent |
| 167 |
community.general.keycloak_component_info: |
| 168 |
auth_keycloak_url: "{{ url }}" |
| 169 |
auth_realm: "{{ admin_realm }}" |
| 170 |
auth_username: "{{ admin_user }}" |
| 171 |
auth_password: "{{ admin_password }}" |
| 172 |
name: "{{ realm_key_name }}" |
| 173 |
provider_type: "org.keycloak.keys.KeyProvider" |
| 174 |
realm: "{{ realm }}" |
| 175 |
register: result |
| 176 |
|
| 177 |
- name: Assert key is missing |
| 178 |
assert: |
| 179 |
that: |
| 180 |
- result is not changed |
| 181 |
- result.components | length == 0 |
| 182 |
|
| 183 |
- name: Create custom realm key |
| 184 |
community.general.keycloak_realm_key: |
| 185 |
auth_keycloak_url: "{{ url }}" |
| 186 |
auth_realm: "{{ admin_realm }}" |
| 187 |
auth_username: "{{ admin_user }}" |
| 188 |
auth_password: "{{ admin_password }}" |
| 189 |
name: "{{ realm_key_name }}" |
| 190 |
state: present |
| 191 |
parent_id: "{{ realm }}" |
| 192 |
config: |
| 193 |
private_key: "{{ realm_private_key }}" |
| 194 |
certificate: "" |
| 195 |
enabled: true |
| 196 |
active: true |
| 197 |
priority: 150 |
| 198 |
register: result |
| 199 |
|
| 200 |
- name: Retrive key info |
| 201 |
community.general.keycloak_component_info: |
| 202 |
auth_keycloak_url: "{{ url }}" |
| 203 |
auth_realm: "{{ admin_realm }}" |
| 204 |
auth_username: "{{ admin_user }}" |
| 205 |
auth_password: "{{ admin_password }}" |
| 206 |
name: "{{ realm_key_name }}" |
| 207 |
provider_type: "org.keycloak.keys.KeyProvider" |
| 208 |
realm: "{{ realm }}" |
| 209 |
register: result |
| 210 |
|
| 211 |
- name: Assert key exists |
| 212 |
assert: |
| 213 |
that: |
| 214 |
- result is not changed |
| 215 |
- result.components | length == 1 |
| 216 |
|
| 217 |
- name: Retrive all realm components |
| 218 |
community.general.keycloak_component_info: |
| 219 |
auth_keycloak_url: "{{ url }}" |
| 220 |
auth_realm: "{{ admin_realm }}" |
| 221 |
auth_username: "{{ admin_user }}" |
| 222 |
auth_password: "{{ admin_password }}" |
| 223 |
realm: "{{ realm }}" |
| 224 |
register: result |
| 225 |
|
| 226 |
- name: Assert key exists |
| 227 |
assert: |
| 228 |
that: |
| 229 |
- result is not changed |
| 230 |
- result.components | length > 0 |
| 231 |
|
| 232 |
- name: Retrive all ldap in realm |
| 233 |
community.general.keycloak_component_info: |
| 234 |
auth_keycloak_url: "{{ url }}" |
| 235 |
auth_realm: "{{ admin_realm }}" |
| 236 |
auth_username: "{{ admin_user }}" |
| 237 |
auth_password: "{{ admin_password }}" |
| 238 |
realm: "{{ realm }}" |
| 239 |
provider_type: "org.keycloak.storage.UserStorageProvider" |
| 240 |
register: result |
| 241 |
|
| 242 |
- name: Assert key exists |
| 243 |
assert: |
| 244 |
that: |
| 245 |
- result is not changed |
| 246 |
- result.components | length == 1 |
| 247 |
- result.components[0].providerType == "org.keycloak.storage.UserStorageProvider" |
| 248 |
- result.components[0].name == "myldap" |
| 249 |
|
| 250 |
- name: Retrive component by name only |
| 251 |
community.general.keycloak_component_info: |
| 252 |
auth_keycloak_url: "{{ url }}" |
| 253 |
auth_realm: "{{ admin_realm }}" |
| 254 |
auth_username: "{{ admin_user }}" |
| 255 |
auth_password: "{{ admin_password }}" |
| 256 |
realm: "{{ realm }}" |
| 257 |
name: "{{ realm_key_name }}" |
| 258 |
register: result |
| 259 |
|
| 260 |
- name: Assert key exists |
| 261 |
assert: |
| 262 |
that: |
| 263 |
- result is not changed |
| 264 |
- result.components | length == 1 |
| 265 |
- result.components[0].providerType == "org.keycloak.keys.KeyProvider" |
| 266 |
- result.components[0].name == realm_key_name |