Debian Codegraph @

ansible_collections/community/aws/tests/integration/targets/iam_server_certificate/tasks/main.yml

raw
1 ---
2 # iam_server_certificate integration tests
3 #
4 # Note:
5 #
6 # AWS APIs only support renaming and/or updating
7 # the *path*.
8 #
9 # It is not possible to update the cert/key/chain
10 # without deleting the ceritifate
11 #
12 - module_defaults:
13 group/aws:
14 access_key: '{{ aws_access_key }}'
15 secret_key: '{{ aws_secret_key }}'
16 session_token: '{{ security_token | default(omit) }}'
17 region: '{{ aws_region }}'
18 block:
19 ################################################
20
21 - name: Test with no args
22 iam_server_certificate: {}
23 ignore_errors: true
24 register: no_args
25
26 - assert:
27 that:
28 - no_args is failed
29 - no_args.msg.startswith('missing required arguments')
30
31 ################################################
32
33 - include_tasks: 'generate-certs.yml'
34
35 ################################################
36
37 - set_fact:
38 cert_a_data: '{{ lookup("file", path_cert_a) }}'
39 cert_b_data: '{{ lookup("file", path_cert_b) }}'
40 chain_cert_data: '{{ lookup("file", path_intermediate_cert) }}'
41
42 - name: Create Certificate - check_mode
43 iam_server_certificate:
44 name: '{{ cert_name }}'
45 state: present
46 cert: '{{ cert_a_data }}'
47 key: '{{ lookup("file", path_cert_key) }}'
48 register: create_cert
49 check_mode: true
50
51 - name: check result - Create Certificate - check_mode
52 assert:
53 that:
54 - create_cert is successful
55 - create_cert is changed
56
57 - name: Create Certificate
58 iam_server_certificate:
59 name: '{{ cert_name }}'
60 state: present
61 cert: '{{ cert_a_data }}'
62 key: '{{ lookup("file", path_cert_key) }}'
63 register: create_cert
64
65 - name: check result - Create Certificate
66 assert:
67 that:
68 - create_cert is successful
69 - create_cert is changed
70 - '"arn" in create_cert'
71 - '"cert_body" in create_cert'
72 - '"cert_path" in create_cert'
73 - '"expiration_date" in create_cert'
74 - '"name" in create_cert'
75 - '"upload_date" in create_cert'
76 - create_cert.arn.startswith('arn:aws')
77 - create_cert.arn.endswith(cert_name)
78 - create_cert.name == cert_name
79 - create_cert.cert_path == '/'
80 - create_cert.cert_body == cert_a_data
81
82 - name: Create Certificate - idempotency - check_mode
83 iam_server_certificate:
84 name: '{{ cert_name }}'
85 state: present
86 cert: '{{ cert_a_data }}'
87 key: '{{ lookup("file", path_cert_key) }}'
88 register: create_cert
89 check_mode: true
90
91 - name: check result - Create Certificate - idempotency
92 assert:
93 that:
94 - create_cert is successful
95 - create_cert is not changed
96
97 - name: Create Certificate - idempotency
98 iam_server_certificate:
99 name: '{{ cert_name }}'
100 state: present
101 cert: '{{ cert_a_data }}'
102 key: '{{ lookup("file", path_cert_key) }}'
103 register: create_cert
104
105 - name: check result - Create Certificate - idempotency
106 assert:
107 that:
108 - create_cert is successful
109 - create_cert is not changed
110 - '"arn" in create_cert'
111 - '"cert_body" in create_cert'
112 - '"cert_path" in create_cert'
113 - '"expiration_date" in create_cert'
114 - '"name" in create_cert'
115 - '"upload_date" in create_cert'
116 - create_cert.arn.startswith('arn:aws')
117 - create_cert.arn.endswith(cert_name)
118 - create_cert.name == cert_name
119 - create_cert.cert_path == '/'
120 - create_cert.cert_body == cert_a_data
121
122 ################################################
123
124 # Module explicitly blocks updating certs
125 - name: Update Certificate - check_mode
126 iam_server_certificate:
127 name: '{{ cert_name }}'
128 state: present
129 cert: '{{ cert_b_data }}'
130 register: update_cert
131 ignore_errors: true
132 check_mode: true
133
134 - name: check result - Update Certificate - check_mode
135 assert:
136 that:
137 - update_cert is failed
138 - '"not supported" in update_cert.msg'
139
140 - name: Update Certificate
141 iam_server_certificate:
142 name: '{{ cert_name }}'
143 state: present
144 cert: '{{ cert_b_data }}'
145 register: update_cert
146 ignore_errors: true
147
148 - name: check result - Update Certificate
149 assert:
150 that:
151 - update_cert is failed
152 - '"not supported" in update_cert.msg'
153
154 - name: Update Chaining Certificate - check_mode
155 iam_server_certificate:
156 name: '{{ cert_name }}'
157 state: present
158 cert_chain: '{{ chain_cert_data }}'
159 register: update_cert
160 ignore_errors: true
161 check_mode: true
162
163 - name: check result - Update Chaining Certificate - check_mode
164 assert:
165 that:
166 - update_cert is failed
167 - '"not supported" in update_cert.msg'
168
169 - name: Update Chaining Certificate
170 iam_server_certificate:
171 name: '{{ cert_name }}'
172 state: present
173 cert_chain: '{{ chain_cert_data }}'
174 register: update_cert
175 ignore_errors: true
176
177 - name: check result - Update Chaining Certificate
178 assert:
179 that:
180 - update_cert is failed
181 - '"not supported" in update_cert.msg'
182
183 # AWS APIs provide no mechanism for accessing
184 # any information about the key, and as such
185 # the module can't tell if a key was updated.
186
187 ################################################
188
189 - name: Delete certificate - check_mode
190 iam_server_certificate:
191 name: '{{ cert_name }}'
192 state: absent
193 register: delete_cert
194 check_mode: true
195
196 - name: check result - Delete certificate - check_mode
197 assert:
198 that:
199 - delete_cert is successful
200 - delete_cert is changed
201
202 - name: Delete certificate
203 iam_server_certificate:
204 name: '{{ cert_name }}'
205 state: absent
206 register: delete_cert
207
208 - name: check result - Delete certificate
209 assert:
210 that:
211 - delete_cert is successful
212 - delete_cert is changed
213
214 - name: Delete certificate - idempotency - check_mode
215 iam_server_certificate:
216 name: '{{ cert_name }}'
217 state: absent
218 register: delete_cert
219 check_mode: true
220
221 - name: check result - Delete certificate - check_mode
222 assert:
223 that:
224 - delete_cert is successful
225 - delete_cert is not changed
226
227 - name: Delete certificate - idempotency
228 iam_server_certificate:
229 name: '{{ cert_name }}'
230 state: absent
231 register: delete_cert
232
233 - name: check result - Delete certificate
234 assert:
235 that:
236 - delete_cert is successful
237 - delete_cert is not changed
238
239 ################################################
240
241 - name: Create Certificate with Chain and path - check_mode
242 iam_server_certificate:
243 name: '{{ cert_name }}'
244 state: present
245 cert: '{{ cert_a_data }}'
246 key: '{{ lookup("file", path_cert_key) }}'
247 cert_chain: '{{ chain_cert_data }}'
248 path: '/ansible-test-example/'
249 register: create_cert
250 check_mode: true
251
252 - name: check result - Create Certificate with Chain and path - check_mode
253 assert:
254 that:
255 - create_cert is successful
256 - create_cert is changed
257
258 - name: Create Certificate with Chain and path
259 iam_server_certificate:
260 name: '{{ cert_name }}'
261 state: present
262 cert: '{{ cert_a_data }}'
263 key: '{{ lookup("file", path_cert_key) }}'
264 cert_chain: '{{ chain_cert_data }}'
265 path: '/ansible-test-example/'
266 register: create_cert
267
268 - name: check result - Create Certificate with Chain and path
269 assert:
270 that:
271 - create_cert is successful
272 - create_cert is changed
273 - '"arn" in create_cert'
274 - '"cert_body" in create_cert'
275 - '"cert_path" in create_cert'
276 - '"expiration_date" in create_cert'
277 - '"name" in create_cert'
278 - '"upload_date" in create_cert'
279 - create_cert.arn.startswith('arn:aws')
280 - create_cert.arn.endswith(cert_name)
281 - create_cert.name == cert_name
282 - create_cert.cert_path == '/ansible-test-example/'
283 - create_cert.cert_body == cert_a_data
284
285 - name: Create Certificate with Chain and path - idempotency - check_mode
286 iam_server_certificate:
287 name: '{{ cert_name }}'
288 state: present
289 cert: '{{ cert_a_data }}'
290 key: '{{ lookup("file", path_cert_key) }}'
291 cert_chain: '{{ chain_cert_data }}'
292 path: '/ansible-test-example/'
293 register: create_cert
294 check_mode: true
295
296 - name: check result - Create Certificate with Chain and path - idempotency - check_mode
297 assert:
298 that:
299 - create_cert is successful
300 - create_cert is not changed
301
302 - name: Create Certificate with Chain and path - idempotency
303 iam_server_certificate:
304 name: '{{ cert_name }}'
305 state: present
306 cert: '{{ cert_a_data }}'
307 key: '{{ lookup("file", path_cert_key) }}'
308 cert_chain: '{{ chain_cert_data }}'
309 path: '/ansible-test-example/'
310 register: create_cert
311
312 - name: check result - Create Certificate with Chain and path - idempotency
313 assert:
314 that:
315 - create_cert is successful
316 - create_cert is not changed
317 - '"arn" in create_cert'
318 - '"cert_body" in create_cert'
319 - '"cert_path" in create_cert'
320 - '"expiration_date" in create_cert'
321 - '"name" in create_cert'
322 - '"upload_date" in create_cert'
323 - create_cert.arn.startswith('arn:aws')
324 - create_cert.arn.endswith(cert_name)
325 - create_cert.name == cert_name
326 - create_cert.cert_path == '/ansible-test-example/'
327 - create_cert.cert_body == cert_a_data
328
329 ################################################
330
331 - name: Create Certificate with identical cert dup_ok=False - check_mode
332 iam_server_certificate:
333 name: '{{ cert_name }}-duplicate'
334 state: present
335 cert: '{{ cert_a_data }}'
336 key: '{{ lookup("file", path_cert_key) }}'
337 dup_ok: false
338 register: create_duplicate
339 ignore_errors: true
340
341 - name: check result - Create Certificate with identical cert - check_mode
342 assert:
343 that:
344 - create_duplicate is failed
345
346 - name: Create Certificate with identical cert dup_ok=False
347 iam_server_certificate:
348 name: '{{ cert_name }}-duplicate'
349 state: present
350 cert: '{{ cert_a_data }}'
351 key: '{{ lookup("file", path_cert_key) }}'
352 dup_ok: false
353 register: create_duplicate
354 ignore_errors: true
355
356 - name: check result - Create Certificate with identical cert
357 assert:
358 that:
359 - create_duplicate is failed
360
361 ################################################
362
363 - name: Create Certificate with forced identical cert - check_mode
364 iam_server_certificate:
365 name: '{{ cert_name }}-duplicate'
366 state: present
367 cert: '{{ cert_a_data }}'
368 key: '{{ lookup("file", path_cert_key) }}'
369 register: create_duplicate
370 check_mode: true
371
372 - name: check result - Create Certificate with forced identical cert - check_mode
373 assert:
374 that:
375 - create_duplicate is successful
376 - create_duplicate is changed
377
378 - name: Create Certificate with forced identical cert
379 iam_server_certificate:
380 name: '{{ cert_name }}-duplicate'
381 state: present
382 cert: '{{ cert_a_data }}'
383 key: '{{ lookup("file", path_cert_key) }}'
384 register: create_duplicate
385
386 - name: check result - Create Certificate with forced identical cert
387 assert:
388 that:
389 - create_duplicate is successful
390 - create_duplicate is changed
391 - '"arn" in create_duplicate'
392 - '"cert_body" in create_duplicate'
393 - '"cert_path" in create_duplicate'
394 - '"expiration_date" in create_duplicate'
395 - '"name" in create_duplicate'
396 - '"upload_date" in create_duplicate'
397 - create_duplicate.arn.startswith('arn:aws')
398 - create_duplicate.arn.endswith('-duplicate')
399 - create_duplicate.name.endswith('duplicate')
400 - create_duplicate.cert_path == '/'
401 - create_duplicate.cert_body == cert_a_data
402
403 - name: Create Certificate with forced identical cert - idempotency - check_mode
404 iam_server_certificate:
405 name: '{{ cert_name }}-duplicate'
406 state: present
407 cert: '{{ cert_a_data }}'
408 key: '{{ lookup("file", path_cert_key) }}'
409 register: create_duplicate
410 check_mode: true
411
412 - name: check result - Create Certificate with forced identical cert - idempotency - check_mode
413 assert:
414 that:
415 - create_duplicate is successful
416 - create_duplicate is not changed
417
418 - name: Create Certificate with forced identical cert - idempotency
419 iam_server_certificate:
420 name: '{{ cert_name }}-duplicate'
421 state: present
422 cert: '{{ cert_a_data }}'
423 key: '{{ lookup("file", path_cert_key) }}'
424 register: create_duplicate
425
426 - name: check result - Create Certificate with forced identical cert - idempotency
427 assert:
428 that:
429 - create_duplicate is successful
430 - create_duplicate is not changed
431 - '"arn" in create_duplicate'
432 - '"cert_body" in create_duplicate'
433 - '"cert_path" in create_duplicate'
434 - '"expiration_date" in create_duplicate'
435 - '"name" in create_duplicate'
436 - '"upload_date" in create_duplicate'
437 - create_duplicate.arn.startswith('arn:aws')
438 - create_duplicate.arn.endswith('-duplicate')
439 - create_duplicate.name.endswith('duplicate')
440 - create_duplicate.cert_path == '/'
441 - create_duplicate.cert_body == cert_a_data
442
443 ################################################
444
445 - name: Update certificate path - check_mode
446 iam_server_certificate:
447 name: '{{ cert_name }}'
448 state: present
449 path: '/ansible-test-example/'
450 new_path: '/ansible-test-path/'
451 register: update_path
452 check_mode: true
453
454 - name: check result - Update certificate path - check_mode
455 assert:
456 that:
457 - update_path is successful
458 - update_path is changed
459
460 - name: Update certificate path
461 iam_server_certificate:
462 name: '{{ cert_name }}'
463 state: present
464 path: '/ansible-test-example/'
465 new_path: '/ansible-test-path/'
466 register: update_path
467
468 - name: check result - Update certificate path
469 assert:
470 that:
471 - update_path is successful
472 - update_path is changed
473 - '"arn" in update_path'
474 - '"cert_body" in update_path'
475 - '"cert_path" in update_path'
476 - '"expiration_date" in update_path'
477 - '"name" in update_path'
478 - '"upload_date" in update_path'
479 - update_path.arn.startswith('arn:aws')
480 - update_path.arn.endswith(cert_name)
481 - update_path.name == cert_name
482 - update_path.cert_path == '/ansible-test-path/'
483 - update_path.cert_body == cert_a_data
484
485 - name: Update certificate path - idempotency - check_mode
486 iam_server_certificate:
487 name: '{{ cert_name }}'
488 state: present
489 path: '/ansible-test-example/'
490 new_path: '/ansible-test-path/'
491 register: update_path
492 check_mode: true
493
494 - name: check result - Update certificate path - idempotency - check_mode
495 assert:
496 that:
497 - update_path is successful
498 - update_path is not changed
499
500 - name: Update certificate path - idempotency
501 iam_server_certificate:
502 name: '{{ cert_name }}'
503 state: present
504 path: '/ansible-test-example/'
505 new_path: '/ansible-test-path/'
506 register: update_path
507
508 - name: check result - Update certificate path - idempotency
509 assert:
510 that:
511 - update_path is successful
512 - update_path is not changed
513
514 ################################################
515
516 - name: Update certificate name - check_mode
517 iam_server_certificate:
518 name: '{{ cert_name }}'
519 new_name: '{{ cert_name }}-renamed'
520 state: present
521 register: update_name
522 check_mode: true
523
524 - name: check result - Update certificate name - check_mode
525 assert:
526 that:
527 - update_name is successful
528 - update_name is changed
529
530 - name: Update certificate name
531 iam_server_certificate:
532 name: '{{ cert_name }}'
533 new_name: '{{ cert_name }}-renamed'
534 state: present
535 register: update_name
536
537 - name: check result - Update certificate name
538 assert:
539 that:
540 - update_name is successful
541 - update_name is changed
542 - '"arn" in update_name'
543 - '"cert_body" in update_name'
544 - '"cert_path" in update_name'
545 - '"expiration_date" in update_name'
546 - '"name" in update_name'
547 - '"upload_date" in update_name'
548 - update_name.arn.startswith('arn:aws')
549 - update_name.arn.endswith('-renamed')
550 - update_name.name.endswith('renamed')
551 - update_name.cert_path == '/ansible-test-path/'
552 - update_name.cert_body == cert_a_data
553
554 - name: Update certificate name - idempotency - check_mode
555 iam_server_certificate:
556 name: '{{ cert_name }}'
557 new_name: '{{ cert_name }}-renamed'
558 state: present
559 register: update_name
560 check_mode: true
561
562 - name: check result - Update certificate name - idempotency - check_mode
563 assert:
564 that:
565 - update_name is successful
566 - update_name is not changed
567
568 - name: Update certificate name - idempotency
569 iam_server_certificate:
570 name: '{{ cert_name }}'
571 new_name: '{{ cert_name }}-renamed'
572 state: present
573 register: update_name
574
575 - name: check result - Update certificate name - idempotency
576 assert:
577 that:
578 - update_name is successful
579 - update_name is not changed
580 - '"arn" in update_name'
581 - '"cert_body" in update_name'
582 - '"cert_path" in update_name'
583 - '"expiration_date" in update_name'
584 - '"name" in update_name'
585 - '"upload_date" in update_name'
586 - update_name.arn.startswith('arn:aws')
587 - update_name.arn.endswith('-renamed')
588 - update_name.name.endswith('renamed')
589 - update_name.cert_path == '/ansible-test-path/'
590 - update_name.cert_body == cert_a_data
591
592 always:
593
594 ################################################
595 # TEARDOWN STARTS HERE
596 ################################################
597
598 - name: Delete certificate
599 iam_server_certificate:
600 name: '{{ item }}'
601 state: absent
602 ignore_errors: true
603 loop:
604 - '{{ cert_name }}'
605 - '{{ cert_name }}-renamed'
606 - '{{ cert_name }}-duplicate'