| 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: Start container |
| 6 |
community.docker.docker_container: |
| 7 |
name: mykeycloak |
| 8 |
image: "quay.io/keycloak/keycloak:24.0.5" |
| 9 |
command: start-dev |
| 10 |
env: |
| 11 |
KC_HTTP_RELATIVE_PATH: /auth |
| 12 |
KEYCLOAK_ADMIN: admin |
| 13 |
KEYCLOAK_ADMIN_PASSWORD: password |
| 14 |
ports: |
| 15 |
- "8080:8080" |
| 16 |
detach: true |
| 17 |
auto_remove: true |
| 18 |
memory: 2200M |
| 19 |
|
| 20 |
- name: Check default ports |
| 21 |
ansible.builtin.wait_for: |
| 22 |
host: "localhost" |
| 23 |
port: "8080" |
| 24 |
state: started # Port should be open |
| 25 |
delay: 30 # Wait before first check |
| 26 |
timeout: 50 # Stop checking after timeout (sec) |
| 27 |
|
| 28 |
- name: Remove Keycloak test realm to avoid failures from previous failed runs |
| 29 |
community.general.keycloak_realm: |
| 30 |
auth_keycloak_url: "{{ url }}" |
| 31 |
auth_realm: "{{ admin_realm }}" |
| 32 |
auth_username: "{{ admin_user }}" |
| 33 |
auth_password: "{{ admin_password }}" |
| 34 |
realm: "{{ realm }}" |
| 35 |
id: "{{ realm }}" |
| 36 |
state: absent |
| 37 |
|
| 38 |
- name: Create Keycloak test realm |
| 39 |
community.general.keycloak_realm: |
| 40 |
auth_keycloak_url: "{{ url }}" |
| 41 |
auth_realm: "{{ admin_realm }}" |
| 42 |
auth_username: "{{ admin_user }}" |
| 43 |
auth_password: "{{ admin_password }}" |
| 44 |
realm: "{{ realm }}" |
| 45 |
id: "{{ realm }}" |
| 46 |
state: present |
| 47 |
|
| 48 |
- name: Create default User Profile (check mode) |
| 49 |
community.general.keycloak_userprofile: |
| 50 |
auth_keycloak_url: "{{ url }}" |
| 51 |
auth_realm: "{{ admin_realm }}" |
| 52 |
auth_username: "{{ admin_user }}" |
| 53 |
auth_password: "{{ admin_password }}" |
| 54 |
parent_id: "{{ realm }}" |
| 55 |
config: "{{ config_default }}" |
| 56 |
check_mode: true |
| 57 |
register: result |
| 58 |
|
| 59 |
- name: Assert that User Profile would be created |
| 60 |
assert: |
| 61 |
that: |
| 62 |
- result is changed |
| 63 |
- result.end_state != {} |
| 64 |
- result.end_state.providerId == "declarative-user-profile" |
| 65 |
- result.end_state.providerType == "org.keycloak.userprofile.UserProfileProvider" |
| 66 |
- result.msg == "Userprofile declarative-user-profile would be created" |
| 67 |
|
| 68 |
- name: Create default User Profile |
| 69 |
community.general.keycloak_userprofile: |
| 70 |
auth_keycloak_url: "{{ url }}" |
| 71 |
auth_realm: "{{ admin_realm }}" |
| 72 |
auth_username: "{{ admin_user }}" |
| 73 |
auth_password: "{{ admin_password }}" |
| 74 |
state: present |
| 75 |
parent_id: "{{ realm }}" |
| 76 |
config: "{{ config_default }}" |
| 77 |
diff: true |
| 78 |
register: result |
| 79 |
|
| 80 |
- name: Assert that User Profile was created |
| 81 |
assert: |
| 82 |
that: |
| 83 |
- result is changed |
| 84 |
- result.end_state != {} |
| 85 |
- result.end_state.providerId == "declarative-user-profile" |
| 86 |
- result.end_state.providerType == "org.keycloak.userprofile.UserProfileProvider" |
| 87 |
- result.msg == "Userprofile declarative-user-profile created" |
| 88 |
|
| 89 |
- name: Create default User Profile (test for idempotency) |
| 90 |
community.general.keycloak_userprofile: |
| 91 |
auth_keycloak_url: "{{ url }}" |
| 92 |
auth_realm: "{{ admin_realm }}" |
| 93 |
auth_username: "{{ admin_user }}" |
| 94 |
auth_password: "{{ admin_password }}" |
| 95 |
state: present |
| 96 |
parent_id: "{{ realm }}" |
| 97 |
config: "{{ config_default }}" |
| 98 |
register: result |
| 99 |
|
| 100 |
- name: Assert that User Profile was in sync |
| 101 |
assert: |
| 102 |
that: |
| 103 |
- result is not changed |
| 104 |
- result.end_state != {} |
| 105 |
- result.end_state.providerId == "declarative-user-profile" |
| 106 |
- result.end_state.providerType == "org.keycloak.userprofile.UserProfileProvider" |
| 107 |
- result.msg == "Userprofile declarative-user-profile was in sync" |
| 108 |
|
| 109 |
- name: Update default User Profile (check mode) |
| 110 |
community.general.keycloak_userprofile: |
| 111 |
auth_keycloak_url: "{{ url }}" |
| 112 |
auth_realm: "{{ admin_realm }}" |
| 113 |
auth_username: "{{ admin_user }}" |
| 114 |
auth_password: "{{ admin_password }}" |
| 115 |
state: present |
| 116 |
parent_id: "{{ realm }}" |
| 117 |
config: "{{ config_updated }}" |
| 118 |
check_mode: true |
| 119 |
register: result |
| 120 |
|
| 121 |
- name: Assert that User Profile would be changed |
| 122 |
assert: |
| 123 |
that: |
| 124 |
- result is changed |
| 125 |
- result.end_state != {} |
| 126 |
- result.end_state.providerId == "declarative-user-profile" |
| 127 |
- result.end_state.providerType == "org.keycloak.userprofile.UserProfileProvider" |
| 128 |
- result.msg.startswith("Userprofile declarative-user-profile would be changed:") |
| 129 |
|
| 130 |
- name: Update default User Profile |
| 131 |
community.general.keycloak_userprofile: |
| 132 |
auth_keycloak_url: "{{ url }}" |
| 133 |
auth_realm: "{{ admin_realm }}" |
| 134 |
auth_username: "{{ admin_user }}" |
| 135 |
auth_password: "{{ admin_password }}" |
| 136 |
state: present |
| 137 |
parent_id: "{{ realm }}" |
| 138 |
config: "{{ config_updated }}" |
| 139 |
diff: true |
| 140 |
register: result |
| 141 |
|
| 142 |
- name: Assert that User Profile changed |
| 143 |
assert: |
| 144 |
that: |
| 145 |
- result is changed |
| 146 |
- result.end_state != {} |
| 147 |
- result.end_state.providerId == "declarative-user-profile" |
| 148 |
- result.end_state.providerType == "org.keycloak.userprofile.UserProfileProvider" |
| 149 |
- result.msg.startswith("Userprofile declarative-user-profile changed:") |
| 150 |
|
| 151 |
- name: Update default User Profile (test for idempotency) |
| 152 |
community.general.keycloak_userprofile: |
| 153 |
auth_keycloak_url: "{{ url }}" |
| 154 |
auth_realm: "{{ admin_realm }}" |
| 155 |
auth_username: "{{ admin_user }}" |
| 156 |
auth_password: "{{ admin_password }}" |
| 157 |
state: present |
| 158 |
parent_id: "{{ realm }}" |
| 159 |
config: "{{ config_updated }}" |
| 160 |
register: result |
| 161 |
|
| 162 |
- name: Assert that User Profile was in sync |
| 163 |
assert: |
| 164 |
that: |
| 165 |
- result is not changed |
| 166 |
- result.end_state != {} |
| 167 |
- result.end_state.providerId == "declarative-user-profile" |
| 168 |
- result.end_state.providerType == "org.keycloak.userprofile.UserProfileProvider" |
| 169 |
- result.msg == "Userprofile declarative-user-profile was in sync" |
| 170 |
|
| 171 |
## No force implemented |
| 172 |
# - name: Force update default User Profile |
| 173 |
# community.general.keycloak_userprofile: |
| 174 |
# auth_keycloak_url: "{{ url }}" |
| 175 |
# auth_realm: "{{ admin_realm }}" |
| 176 |
# auth_username: "{{ admin_user }}" |
| 177 |
# auth_password: "{{ admin_password }}" |
| 178 |
# force: true |
| 179 |
# state: present |
| 180 |
# parent_id: "{{ realm }}" |
| 181 |
# config: "{{ config_updated }}" |
| 182 |
# register: result |
| 183 |
# |
| 184 |
# - name: Assert that forced update ran correctly |
| 185 |
# assert: |
| 186 |
# that: |
| 187 |
# - result is changed |
| 188 |
# - result.end_state != {} |
| 189 |
# - result.end_state.providerId == "declarative-user-profile" |
| 190 |
# - result.end_state.providerType == "org.keycloak.userprofile.UserProfileProvider" |
| 191 |
# - result.msg == "Userprofile declarative-user-profile was forcibly updated" |
| 192 |
|
| 193 |
- name: Remove default User Profile |
| 194 |
community.general.keycloak_userprofile: |
| 195 |
auth_keycloak_url: "{{ url }}" |
| 196 |
auth_realm: "{{ admin_realm }}" |
| 197 |
auth_username: "{{ admin_user }}" |
| 198 |
auth_password: "{{ admin_password }}" |
| 199 |
state: absent |
| 200 |
parent_id: "{{ realm }}" |
| 201 |
config: "{{ config_default }}" |
| 202 |
diff: true |
| 203 |
register: result |
| 204 |
|
| 205 |
- name: Assert that User Profile was deleted |
| 206 |
assert: |
| 207 |
that: |
| 208 |
- result is changed |
| 209 |
- result.end_state == {} |
| 210 |
- result.msg == "Userprofile declarative-user-profile deleted" |
| 211 |
|
| 212 |
- name: Remove default User Profile (test for idempotency) |
| 213 |
community.general.keycloak_userprofile: |
| 214 |
auth_keycloak_url: "{{ url }}" |
| 215 |
auth_realm: "{{ admin_realm }}" |
| 216 |
auth_username: "{{ admin_user }}" |
| 217 |
auth_password: "{{ admin_password }}" |
| 218 |
state: absent |
| 219 |
parent_id: "{{ realm }}" |
| 220 |
config: "{{ config_default }}" |
| 221 |
register: result |
| 222 |
|
| 223 |
- name: Assert that User Profile not present |
| 224 |
assert: |
| 225 |
that: |
| 226 |
- result is not changed |
| 227 |
- result.end_state == {} |
| 228 |
- result.msg == "Userprofile declarative-user-profile not present" |
| 229 |
|
| 230 |
- name: Create User Profile with unmanaged attributes ENABLED |
| 231 |
community.general.keycloak_userprofile: |
| 232 |
auth_keycloak_url: "{{ url }}" |
| 233 |
auth_realm: "{{ admin_realm }}" |
| 234 |
auth_username: "{{ admin_user }}" |
| 235 |
auth_password: "{{ admin_password }}" |
| 236 |
state: present |
| 237 |
parent_id: "{{ realm }}" |
| 238 |
config: "{{ config_unmanaged_attributes_enabled }}" |
| 239 |
diff: true |
| 240 |
register: result |
| 241 |
|
| 242 |
- name: Assert that User Profile was created |
| 243 |
assert: |
| 244 |
that: |
| 245 |
- result is changed |
| 246 |
- result.end_state != {} |
| 247 |
- result.end_state.providerId == "declarative-user-profile" |
| 248 |
- result.end_state.providerType == "org.keycloak.userprofile.UserProfileProvider" |
| 249 |
- result.msg == "Userprofile declarative-user-profile created" |
| 250 |
|
| 251 |
- name: Attempt to change the User Profile to unmanaged ADMIN_EDIT |
| 252 |
community.general.keycloak_userprofile: |
| 253 |
auth_keycloak_url: "{{ url }}" |
| 254 |
auth_realm: "{{ admin_realm }}" |
| 255 |
auth_username: "{{ admin_user }}" |
| 256 |
auth_password: "{{ admin_password }}" |
| 257 |
state: present |
| 258 |
parent_id: "{{ realm }}" |
| 259 |
config: "{{ config_unmanaged_attributes_admin_edit }}" |
| 260 |
diff: true |
| 261 |
register: result |
| 262 |
|
| 263 |
- name: Assert that User Profile was changed |
| 264 |
assert: |
| 265 |
that: |
| 266 |
- result is changed |
| 267 |
- result.end_state != {} |
| 268 |
- result.end_state.providerId == "declarative-user-profile" |
| 269 |
- result.end_state.providerType == "org.keycloak.userprofile.UserProfileProvider" |
| 270 |
- result.msg.startswith("Userprofile declarative-user-profile changed:") |
| 271 |
|
| 272 |
- name: Attempt to change the User Profile to unmanaged ADMIN_VIEW |
| 273 |
community.general.keycloak_userprofile: |
| 274 |
auth_keycloak_url: "{{ url }}" |
| 275 |
auth_realm: "{{ admin_realm }}" |
| 276 |
auth_username: "{{ admin_user }}" |
| 277 |
auth_password: "{{ admin_password }}" |
| 278 |
state: present |
| 279 |
parent_id: "{{ realm }}" |
| 280 |
config: "{{ config_unmanaged_attributes_admin_view }}" |
| 281 |
diff: true |
| 282 |
register: result |
| 283 |
|
| 284 |
- name: Assert that User Profile was changed |
| 285 |
assert: |
| 286 |
that: |
| 287 |
- result is changed |
| 288 |
- result.end_state != {} |
| 289 |
- result.end_state.providerId == "declarative-user-profile" |
| 290 |
- result.end_state.providerType == "org.keycloak.userprofile.UserProfileProvider" |
| 291 |
- result.msg.startswith("Userprofile declarative-user-profile changed:") |
| 292 |
|
| 293 |
- name: Remove Keycloak test realm |
| 294 |
community.general.keycloak_realm: |
| 295 |
auth_keycloak_url: "{{ url }}" |
| 296 |
auth_realm: "{{ admin_realm }}" |
| 297 |
auth_username: "{{ admin_user }}" |
| 298 |
auth_password: "{{ admin_password }}" |
| 299 |
realm: "{{ realm }}" |
| 300 |
id: "{{ realm }}" |
| 301 |
state: absent |