Debian Codegraph @

ansible_collections/community/general/tests/integration/targets/keycloak_user/tasks/main.yml

raw
1 # Copyright (c) 2022, Dušan Marković (@bratwurzt)
2 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
3 # SPDX-License-Identifier: GPL-3.0-or-later
4
5 - name: Create realm
6 community.general.keycloak_realm:
7 auth_keycloak_url: "{{ url }}"
8 auth_realm: "{{ admin_realm }}"
9 auth_username: "{{ admin_user }}"
10 auth_password: "{{ admin_password }}"
11 id: "{{ realm }}"
12 realm: "{{ realm }}"
13 state: present
14
15 - name: Create new realm role
16 community.general.keycloak_role:
17 auth_keycloak_url: "{{ url }}"
18 auth_realm: "{{ admin_realm }}"
19 auth_username: "{{ admin_user }}"
20 auth_password: "{{ admin_password }}"
21 realm: "{{ realm }}"
22 name: "{{ role }}"
23 description: "{{ description_1 }}"
24 state: present
25
26 - name: Create client
27 community.general.keycloak_client:
28 auth_keycloak_url: "{{ url }}"
29 auth_realm: "{{ admin_realm }}"
30 auth_username: "{{ admin_user }}"
31 auth_password: "{{ admin_password }}"
32 realm: "{{ realm }}"
33 client_id: "{{ client_id }}"
34 service_accounts_enabled: true
35 state: present
36 register: client
37
38
39 - name: Create new client role
40 community.general.keycloak_role:
41 auth_keycloak_url: "{{ url }}"
42 auth_realm: "{{ admin_realm }}"
43 auth_username: "{{ admin_user }}"
44 auth_password: "{{ admin_password }}"
45 realm: "{{ realm }}"
46 client_id: "{{ client_id }}"
47 name: "{{ keycloak_client_role }}"
48 description: "{{ description_1 }}"
49 state: present
50
51 - name: Create new groups
52 community.general.keycloak_group:
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: "{{ item.name }}"
59 state: present
60 with_items: "{{ keycloak_user_groups }}"
61
62 - name: Create user
63 community.general.keycloak_user:
64 auth_keycloak_url: "{{ url }}"
65 auth_username: "{{ admin_user }}"
66 auth_password: "{{ admin_password }}"
67 auth_realm: "{{ admin_realm }}"
68 username: "{{ keycloak_username }}"
69 realm: "{{ realm }}"
70 first_name: Ceciestes
71 last_name: Untestes
72 email: [email protected]
73 groups: "{{ keycloak_user_groups }}"
74 attributes: "{{ keycloak_user_attributes }}"
75 state: present
76 register: create_result
77
78 - name: debug
79 debug:
80 var: create_result
81
82 - name: Assert user is created
83 assert:
84 that:
85 - create_result.changed
86 - create_result.end_state.username == 'test'
87 - create_result.end_state.attributes | length == 3
88 - create_result.end_state.groups | length == 2
89
90 - name: Delete User
91 community.general.keycloak_user:
92 auth_keycloak_url: "{{ url }}"
93 auth_username: "{{ admin_user }}"
94 auth_password: "{{ admin_password }}"
95 auth_realm: "{{ admin_realm }}"
96 username: "{{ keycloak_username }}"
97 realm: "{{ realm }}"
98 first_name: Ceciestes
99 last_name: Untestes
100 email: [email protected]
101 groups: "{{ keycloak_user_groups }}"
102 attributes: "{{ keycloak_user_attributes }}"
103 state: absent
104 register: delete_result
105
106 - name: debug
107 debug:
108 var: delete_result
109
110 - name: Assert user is deleted
111 assert:
112 that:
113 - delete_result.changed
114 - delete_result.end_state | length == 0
115
116 - name: Create user with plus-addressed email
117 community.general.keycloak_user:
118 auth_keycloak_url: "{{ url }}"
119 auth_username: "{{ admin_user }}"
120 auth_password: "{{ admin_password }}"
121 auth_realm: "{{ admin_realm }}"
122 username: "testuser+tag"
123 realm: "{{ realm }}"
124 first_name: Plus
125 last_name: User
126 email: "[email protected]"
127 state: present
128 register: plus_create_result
129
130 - name: Assert plus-addressed user is created
131 assert:
132 that:
133 - plus_create_result.changed
134 - plus_create_result.end_state.username == 'testuser+tag'
135 - plus_create_result.end_state.email == '[email protected]'
136
137 - name: Re-run plus-addressed user creation (idempotency)
138 community.general.keycloak_user:
139 auth_keycloak_url: "{{ url }}"
140 auth_username: "{{ admin_user }}"
141 auth_password: "{{ admin_password }}"
142 auth_realm: "{{ admin_realm }}"
143 username: "testuser+tag"
144 realm: "{{ realm }}"
145 first_name: Plus
146 last_name: User
147 email: "[email protected]"
148 state: present
149 register: plus_idempotent_result
150
151 - name: Assert plus-addressed user is idempotent
152 assert:
153 that:
154 - plus_idempotent_result is not changed
155
156 - name: Delete plus-addressed user
157 community.general.keycloak_user:
158 auth_keycloak_url: "{{ url }}"
159 auth_username: "{{ admin_user }}"
160 auth_password: "{{ admin_password }}"
161 auth_realm: "{{ admin_realm }}"
162 username: "testuser+tag"
163 realm: "{{ realm }}"
164 state: absent
165 register: plus_delete_result
166
167 - name: Assert plus-addressed user is deleted
168 assert:
169 that:
170 - plus_delete_result.changed