Debian Codegraph @

ansible_collections/community/libvirt/tests/integration/targets/virt_secret/tasks/main.yml

raw
1 ---
2 - name: Include OS-specifi variables
3 ansible.builtin.include_vars: '{{ item }}'
4 with_first_found:
5 - "{{ ansible_distribution }}-{{ ansible_distribution_version }}.yml"
6 - "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml"
7 - "{{ ansible_distribution }}.yml"
8 - "default.yml"
9
10 - name: Initialisation tasks
11 block:
12 - name: Install libvirt packages
13 ansible.builtin.package:
14 name: "{{ virt_volume_packages }}"
15
16 - name: Install pip packages
17 ansible.builtin.pip:
18 name: "{{ virt_volume_pip_packages }}"
19 state: present
20
21 - name: Start libvirt
22 ansible.builtin.service:
23 name: libvirtd
24 state: started
25
26 - name: Tests manipulate secrets
27 block:
28 - name: Create new secret using xml definition and command
29 community.libvirt.virt_secret:
30 command: create
31 xml: |
32 <secret ephemeral='no' private='yes'>
33 <uuid>{{ 'test_secret' | to_uuid }}</uuid>
34 <description>test_secret pool secret</description>
35 <usage type='ceph'>
36 <name>test_secret</name>
37 </usage>
38 </secret>
39 register: result
40
41 - name: Assert that creality command was successfull
42 ansible.builtin.assert:
43 that:
44 - result.changed
45 - not result.failed
46
47 - name: Test get_xml by uuid
48 community.libvirt.virt_secret:
49 uuid: "{{ 'test_secret' | to_uuid }}"
50 command: get_xml
51 register: result
52
53 - name: Assert that we were able to retrive created secret xml
54 ansible.builtin.assert:
55 that:
56 - result.secret_xml | length > 0
57 - result.msg == 'Found secret'
58 - not result.failed
59 - not result.changed
60
61 - name: Test get_xml by secret usage
62 community.libvirt.virt_secret:
63 secret:
64 usage: ceph
65 usage_id: test_secret
66 description: changed_test pool secret
67 command: get_xml
68 register: result
69
70 - name: Assert that we were able to retrive created secret xml
71 ansible.builtin.assert:
72 that:
73 - result.secret_xml | length > 0
74 - result.msg == 'Found secret'
75 - not result.failed
76 - not result.changed
77
78 - name: Test get_xml by non-existing id
79 community.libvirt.virt_secret:
80 secret:
81 usage: ceph
82 usage_id: incorrect_one
83 command: get_xml
84 register: result
85
86 - name: Assert that there are no secret found
87 ansible.builtin.assert:
88 that:
89 - result.secret_xml == None
90 - result.msg == 'Secret not found'
91 - not result.failed
92 - not result.changed
93
94 - name: Update secret using xml definition and command
95 community.libvirt.virt_secret:
96 command: create
97 xml: |
98 <secret ephemeral='no' private='yes'>
99 <uuid>{{ 'test_secret' | to_uuid }}</uuid>
100 <description>test_ALT pool secret</description>
101 <usage type='ceph'>
102 <name>test_secret</name>
103 </usage>
104 </secret>
105 register: result
106
107 - name: Assert that module detected changes and applied them
108 ansible.builtin.assert:
109 that:
110 - not result.failed
111 - result.changed
112
113 - name: Again, but specify UUID in a property. No Change expected
114 community.libvirt.virt_secret:
115 uuid: "{{ 'test_secret' | to_uuid }}"
116 command: create
117 xml: |
118 <secret ephemeral='no' private='yes'>
119 <description>test_ALT pool secret</description>
120 <usage type='ceph'>
121 <name>test_secret</name>
122 </usage>
123 </secret>
124 register: result
125
126 - name: Assert no change if data isn't changed
127 ansible.builtin.assert:
128 that:
129 - not result.failed
130 - not result.changed
131 - result.warnings is not defined
132
133 - name: Try to duplicate uuid param with incorrect UUID. No change
134 community.libvirt.virt_secret:
135 uuid: "{{ 'another_name' | to_uuid }}"
136 command: create
137 xml: |
138 <secret ephemeral='no' private='yes'>
139 <uuid>{{ 'test_secret' | to_uuid }}</uuid>
140 <description>test_ALT pool secret</description>
141 <usage type='ceph'>
142 <name>test_secret</name>
143 </usage>
144 </secret>
145 register: result
146
147 - name: Assert warrning present if UUID is defiend multiple times
148 ansible.builtin.assert:
149 that:
150 - not result.failed
151 - not result.changed
152 - result.warnings | length > 0
153
154 - name: Try to change secret, but without UUID supplied.
155 community.libvirt.virt_secret:
156 command: create
157 xml: |
158 <secret ephemeral='no' private='yes'>
159 <description>test_second pool secret</description>
160 <usage type='ceph'>
161 <name>test_secret</name>
162 </usage>
163 </secret>
164 register: result
165
166 - name: Assert changed and check that the change is present in the diff
167 ansible.builtin.assert:
168 that:
169 - not result.failed
170 - result.changed
171 - result.diff.before is defined
172 - result.diff.before | length > 0
173 - "'test_second pool secret' in result.diff.after"
174
175 - name: Repeat of the same request should not show changes
176 community.libvirt.virt_secret:
177 command: create
178 xml: |
179 <secret ephemeral='no' private='yes'>
180 <description>test_second pool secret</description>
181 <usage type='ceph'>
182 <name>test_secret</name>
183 </usage>
184 </secret>
185 register: result
186
187 - name: Assert idempotency using xml definition without UUID defined
188 ansible.builtin.assert:
189 that:
190 - not result.failed
191 - not result.changed
192
193 - name: Change using params. Change expected
194 community.libvirt.virt_secret:
195 uuid: "{{ 'test_secret' | to_uuid }}"
196 secret:
197 ephemeral: false
198 private: true
199 usage: ceph
200 usage_id: test_secret
201 description: changed_test pool secret
202 command: create
203 register: result
204
205 - name: Assert changed state when using params
206 ansible.builtin.assert:
207 that:
208 - not result.failed
209 - result.changed
210 - result.diff.after is defined
211 - "'changed_test pool secret' in result.diff.after"
212
213 - name: Test param defaults and seach using secret uage
214 community.libvirt.virt_secret:
215 secret:
216 usage: ceph
217 usage_id: test_secret
218 description: changed_test pool secret
219 command: create
220 register: result
221
222 - name: Assert not changed state when using expected default params
223 ansible.builtin.assert:
224 that:
225 - not result.failed
226 - not result.changed
227
228 - name: Test using state. No change expected
229 community.libvirt.virt_secret:
230 state: present
231 uuid: "{{ 'test_secret' | to_uuid }}"
232 secret:
233 ephemeral: false
234 private: true
235 usage: ceph
236 usage_id: test_secret
237 description: changed_test pool secret
238 register: result
239
240 - name: Assert not changed when we try to define state instead of command
241 ansible.builtin.assert:
242 that:
243 - not result.failed
244 - not result.changed
245
246 - name: Test volume secret creation using state
247 community.libvirt.virt_secret:
248 state: present
249 # uuid: "{{ 'second_secret' | to_uuid }}"
250 secret:
251 ephemeral: false
252 private: true
253 usage: volume
254 usage_id: /var/lib/libvirt/images/puppyname.img
255 description: Secret puppy name
256 register: result
257
258 - name: Assert volume secret was created
259 ansible.builtin.assert:
260 that:
261 - not result.failed
262 - result.changed
263
264 - name: Test iscsi secret creation using state
265 community.libvirt.virt_secret:
266 state: present
267 uuid: "{{ 'iscsi_secret' | to_uuid }}"
268 secret:
269 ephemeral: false
270 private: true
271 usage: iscsi
272 usage_id: libvirtiscsi
273 description: Passphrase for the iSCSI server
274 register: result
275
276 - name: Assert iscsi secret was created
277 ansible.builtin.assert:
278 that:
279 - not result.failed
280 - result.changed
281
282 - name: Test TLS secret creation using state
283 community.libvirt.virt_secret:
284 state: present
285 uuid: "{{ 'tls_secret' | to_uuid }}"
286 secret:
287 ephemeral: false
288 private: true
289 usage: tls
290 usage_id: TLS_example
291 description: Sample tls secret
292 register: result
293
294 - name: Assert TLS secret was created
295 ansible.builtin.assert:
296 that:
297 - not result.failed
298 - result.changed
299
300 - name: Test vTPM secret creation using state
301 community.libvirt.virt_secret:
302 state: present
303 uuid: "{{ 'vtpm_secret' | to_uuid }}"
304 secret:
305 ephemeral: false
306 private: true
307 usage: vtpm
308 usage_id: VTPM_example
309 description: sample vTPM secret
310 register: result
311
312 - name: Assert vTPM secret was created
313 ansible.builtin.assert:
314 that:
315 - not result.failed
316 - result.changed
317
318 - name: Test list all secrets
319 community.libvirt.virt_secret:
320 command: list_secrets
321 register: result
322
323 - name: Assert that list was successfull
324 ansible.builtin.assert:
325 that:
326 - not result.failed
327 - result.secrets_list | length == 5
328
329 - name: Test define secret. Always produce changed
330 community.libvirt.virt_secret:
331 uuid: "{{ 'test_secret' | to_uuid }}"
332 command: set_value
333 password: somesecureandrandomsecret1234
334 register: result
335
336 - name: Assert that definintion of secret produce changes
337 ansible.builtin.assert:
338 that:
339 - not result.failed
340 - result.changed
341 - "'The value for the secret was successfully set' in result.msg"
342
343 - name: Test delete using state=absent
344 community.libvirt.virt_secret:
345 uuid: "{{ 'test_secret' | to_uuid }}"
346 state: absent
347
348 - name: Cleanup volume secret
349 community.libvirt.virt_secret:
350 state: absent
351 secret:
352 usage: volume
353 usage_id: /var/lib/libvirt/images/puppyname.img
354 register: result
355
356 - name: Assert that volume removal without UUID was successfull
357 ansible.builtin.assert:
358 that:
359 - not result.failed
360 - result.changed
361 always:
362 - name: Cleanup ceph secret
363 community.libvirt.virt_secret:
364 uuid: "{{ 'test_secret' | to_uuid }}"
365 state: absent
366
367 - name: Cleanup volume secret
368 community.libvirt.virt_secret:
369 state: absent
370 secret:
371 usage: volume
372 usage_id: /var/lib/libvirt/images/puppyname.img
373
374 - name: Cleanup iscsi secret
375 community.libvirt.virt_secret:
376 uuid: "{{ 'iscsi_secret' | to_uuid }}"
377 state: absent
378
379 - name: Cleanup TLS secret
380 community.libvirt.virt_secret:
381 uuid: "{{ 'tls_secret' | to_uuid }}"
382 state: absent
383
384 - name: Cleanup vTPM secret
385 community.libvirt.virt_secret:
386 uuid: "{{ 'vtpm_secret' | to_uuid }}"
387 state: absent