Debian Codegraph @

ansible_collections/amazon/aws/tests/integration/targets/route53_zone/tasks/main.yml

raw
1 ---
2 - name: Route53_zone integration tests
3
4 module_defaults:
5 group/aws:
6 access_key: "{{ aws_access_key }}"
7 secret_key: "{{ aws_secret_key }}"
8 session_token: "{{ security_token | default(omit) }}"
9 region: "{{ aws_region }}"
10
11 block:
12 # ============================================================
13
14 - name: Create VPC for use in testing
15 amazon.aws.ec2_vpc_net:
16 name: "{{ resource_prefix }}-vpc"
17 cidr_block: 10.22.32.0/23
18 tags:
19 Name: Ansible ec2_instance Testing VPC
20 tenancy: default
21 register: testing_vpc
22
23 # ============================================================
24 - name: Create a public zone
25 amazon.aws.route53_zone:
26 zone: "{{ resource_prefix }}.public"
27 comment: original comment
28 state: present
29 tags:
30 TestTag: "{{ resource_prefix }}"
31 another_tag: "{{ resource_prefix }} again"
32 register: output
33
34 - ansible.builtin.assert:
35 that:
36 - output.changed
37 - output.comment == 'original comment'
38 - output.name == resource_prefix +'.public.'
39 - output.tags.TestTag == resource_prefix
40 - output.tags.another_tag == resource_prefix +' again'
41 - not output.private_zone
42
43 # ============================================================
44 - name: Create a public zone (CHECK MODE)
45 amazon.aws.route53_zone:
46 zone: "{{ resource_prefix }}.check.public"
47 comment: original comment
48 state: present
49 tags:
50 TestTag: "{{ resource_prefix }}"
51 another_tag: "{{ resource_prefix }} again"
52 register: output
53 check_mode: true
54
55 - ansible.builtin.assert:
56 that:
57 - output.changed
58 - output.comment == 'original comment'
59 - output.name == resource_prefix +'.check.public.'
60 - output.tags.TestTag == resource_prefix
61 - output.tags.another_tag == resource_prefix +' again'
62 - not output.private_zone
63
64 # ============================================================
65 - name: Do an idemptotent update of a public zone
66 amazon.aws.route53_zone:
67 zone: "{{ resource_prefix }}.public"
68 comment: original comment
69 state: present
70 tags:
71 TestTag: "{{ resource_prefix }}"
72 another_tag: "{{ resource_prefix }} again"
73 register: output
74
75 - ansible.builtin.assert:
76 that:
77 - not output.changed
78 - output.comment == 'original comment'
79 - output.name == resource_prefix +'.public.'
80 - output.tags.TestTag == resource_prefix
81 - output.tags.another_tag == resource_prefix +' again'
82 - not output.private_zone
83
84 - name: Do an idemptotent update of a public zone (CHECK MODE)
85 amazon.aws.route53_zone:
86 zone: "{{ resource_prefix }}.public"
87 comment: original comment
88 state: present
89 tags:
90 TestTag: "{{ resource_prefix }}"
91 another_tag: "{{ resource_prefix }} again"
92 register: output
93 check_mode: true
94
95 - ansible.builtin.assert:
96 that:
97 - not output.changed
98 - output.comment == 'original comment'
99 - output.name == resource_prefix +'.public.'
100 - output.tags.TestTag == resource_prefix
101 - output.tags.another_tag == resource_prefix +' again'
102 - not output.private_zone
103
104 # ============================================================
105 - name: Modify tags on a public zone
106 amazon.aws.route53_zone:
107 zone: "{{ resource_prefix }}.public"
108 comment: original comment
109 state: present
110 tags:
111 AnotherTag: "{{ resource_prefix }}.anothertag"
112 purge_tags: true
113 register: output
114
115 - ansible.builtin.assert:
116 that:
117 - output.changed
118 - "'TestTag' not in output.tags"
119 - output.tags.AnotherTag == resource_prefix +'.anothertag'
120
121 # ============================================================
122 - name: Update comment and remove tags of a public zone
123 amazon.aws.route53_zone:
124 zone: "{{ resource_prefix }}.public"
125 comment: updated comment
126 state: present
127 purge_tags: true
128 tags: {}
129 register: output
130
131 - ansible.builtin.assert:
132 that:
133 - output.changed
134 - output.result.comment == "updated comment"
135 - not output.tags
136
137 - name: Update comment and remove tags of a public zone (CHECK MODE)
138 amazon.aws.route53_zone:
139 zone: "{{ resource_prefix }}.public"
140 comment: updated comment for check
141 state: present
142 purge_tags: true
143 tags: {}
144 register: output
145 check_mode: true
146
147 - ansible.builtin.assert:
148 that:
149 - output.changed
150 - output.result.comment == "updated comment for check"
151 - not output.tags
152
153 # ============================================================
154 - name: Delete public zone (CHECK MODE)
155 amazon.aws.route53_zone:
156 zone: "{{ resource_prefix }}.public"
157 state: absent
158 register: output
159 check_mode: true
160
161 - ansible.builtin.assert:
162 that:
163 - output.changed
164 - "'Successfully deleted' in output.result"
165
166 - name: Delete public zone
167 amazon.aws.route53_zone:
168 zone: "{{ resource_prefix }}.public"
169 state: absent
170 register: output
171
172 - ansible.builtin.assert:
173 that:
174 - output.changed
175 - "'Successfully deleted' in output.result"
176
177 # ============================================================
178 - name: Create a private zone (CHECK MODE)
179 amazon.aws.route53_zone:
180 vpc_id: "{{ testing_vpc.vpc.id }}"
181 vpc_region: "{{ aws_region }}"
182 zone: "{{ resource_prefix }}.private"
183 comment: original comment
184 state: present
185 register: output
186 check_mode: true
187
188 - ansible.builtin.assert:
189 that:
190 - output.changed
191
192 - name: Create a private zone
193 amazon.aws.route53_zone:
194 vpc_id: "{{ testing_vpc.vpc.id }}"
195 vpc_region: "{{ aws_region }}"
196 zone: "{{ resource_prefix }}.private"
197 comment: original comment
198 state: present
199 register: output
200
201 - ansible.builtin.assert:
202 that:
203 - output.changed
204 # ============================================================
205 - name: Idemptotent update a private zone
206 amazon.aws.route53_zone:
207 vpc_id: "{{ testing_vpc.vpc.id }}"
208 vpc_region: "{{ aws_region }}"
209 zone: "{{ resource_prefix }}.private"
210 comment: original comment
211 state: present
212 register: output
213
214 - ansible.builtin.assert:
215 that:
216 - not output.changed
217 - "'There is already a private hosted zone in the same region with the same VPC' in output.msg"
218
219 - name: Idemptotent update a private zone (CHECK MODE)
220 amazon.aws.route53_zone:
221 vpc_id: "{{ testing_vpc.vpc.id }}"
222 vpc_region: "{{ aws_region }}"
223 zone: "{{ resource_prefix }}.private"
224 comment: original comment
225 state: present
226 register: output
227 check_mode: true
228
229 - ansible.builtin.assert:
230 that:
231 - not output.changed
232 - "'There is already a private hosted zone in the same region with the same VPC' in output.msg"
233
234 # ============================================================
235 - name: Update private zone comment
236 amazon.aws.route53_zone:
237 vpc_id: "{{ testing_vpc.vpc.id }}"
238 vpc_region: "{{ aws_region }}"
239 zone: "{{ resource_prefix }}.private"
240 comment: updated_comment
241 state: present
242 register: output
243
244 - ansible.builtin.assert:
245 that:
246 - output.changed
247 - output.result.comment == "updated_comment"
248
249 - name: Update private zone comment (CHECK MODE)
250 amazon.aws.route53_zone:
251 vpc_id: "{{ testing_vpc.vpc.id }}"
252 vpc_region: "{{ aws_region }}"
253 zone: "{{ resource_prefix }}.private"
254 comment: updated_comment check
255 state: present
256 register: output
257 check_mode: true
258
259 - ansible.builtin.assert:
260 that:
261 - output.changed
262 - output.result.comment == "updated_comment check"
263
264 # ============================================================
265 - name: Try to delete private zone without setting vpc_id and vpc_region
266 amazon.aws.route53_zone:
267 zone: "{{ resource_prefix }}.private"
268 state: absent
269 register: output
270
271 - ansible.builtin.assert:
272 that:
273 - not output.changed
274 - output.result == 'No zone to delete.'
275
276 - name: Try to delete private zone without setting vpc_id and vpc_region (CHECK MODE)
277 amazon.aws.route53_zone:
278 zone: "{{ resource_prefix }}.private"
279 state: absent
280 register: output
281 check_mode: true
282
283 - ansible.builtin.assert:
284 that:
285 - not output.changed
286 - output.result == 'No zone to delete.'
287
288 # ============================================================
289 - name: Try to delete a public zone that does not exists
290 amazon.aws.route53_zone:
291 zone: "{{ resource_prefix }}.publicfake"
292 comment: original comment
293 state: absent
294 register: output
295
296 - ansible.builtin.assert:
297 that:
298 - not output.changed
299 - output.result == 'No zone to delete.'
300
301 - name: Try to delete a public zone that does not exists (CHECK MODE)
302 amazon.aws.route53_zone:
303 zone: "{{ resource_prefix }}.publicfake"
304 comment: original comment
305 state: absent
306 register: output
307 check_mode: true
308
309 - ansible.builtin.assert:
310 that:
311 - not output.changed
312 - output.result == 'No zone to delete.'
313
314 # ============================================================
315 - name: Delete private zone (CHECK MODE)
316 amazon.aws.route53_zone:
317 vpc_id: "{{ testing_vpc.vpc.id }}"
318 vpc_region: "{{ aws_region }}"
319 zone: "{{ resource_prefix }}.private"
320 state: absent
321 register: output
322 check_mode: true
323
324 - ansible.builtin.assert:
325 that:
326 - output.changed
327 - "'Successfully deleted' in output.result"
328
329 - name: Delete private zone
330 amazon.aws.route53_zone:
331 vpc_id: "{{ testing_vpc.vpc.id }}"
332 vpc_region: "{{ aws_region }}"
333 zone: "{{ resource_prefix }}.private"
334 state: absent
335 register: output
336
337 - ansible.builtin.assert:
338 that:
339 - output.changed
340 - "'Successfully deleted' in output.result"
341
342 # ============================================================
343 - name: Create a private zone (new format) (CHECK MODE)
344 amazon.aws.route53_zone:
345 vpcs:
346 - id: "{{ testing_vpc.vpc.id }}"
347 region: "{{ aws_region }}"
348 zone: "{{ resource_prefix }}.private"
349 comment: original comment
350 state: present
351 register: output
352 check_mode: true
353
354 - ansible.builtin.assert:
355 that:
356 - output.changed
357
358 - name: Create a private zone (new format)
359 amazon.aws.route53_zone:
360 vpcs:
361 - id: "{{ testing_vpc.vpc.id }}"
362 region: "{{ aws_region }}"
363 zone: "{{ resource_prefix }}.private"
364 comment: original comment
365 state: present
366 register: output
367
368 - ansible.builtin.assert:
369 that:
370 - output.changed
371
372 # ============================================================
373 - name: Idemptotent update a private zone (new format) (CHECK MODE)
374 amazon.aws.route53_zone:
375 vpcs:
376 - id: "{{ testing_vpc.vpc.id }}"
377 region: "{{ aws_region }}"
378 zone: "{{ resource_prefix }}.private"
379 comment: original comment
380 state: present
381 register: output
382 check_mode: true
383
384 - ansible.builtin.assert:
385 that:
386 - not output.changed
387 - "'There is already a private hosted zone in the same region with the same VPC' in output.msg"
388
389 - name: Idemptotent update a private zone (new format)
390 amazon.aws.route53_zone:
391 vpcs:
392 - id: "{{ testing_vpc.vpc.id }}"
393 region: "{{ aws_region }}"
394 zone: "{{ resource_prefix }}.private"
395 comment: original comment
396 state: present
397 register: output
398
399 - ansible.builtin.assert:
400 that:
401 - not output.changed
402 - "'There is already a private hosted zone in the same region with the same VPC' in output.msg"
403
404 # ============================================================
405 - name: Update a private zone comment (new format) (CHECK MODE)
406 amazon.aws.route53_zone:
407 vpcs:
408 - id: "{{ testing_vpc.vpc.id }}"
409 region: "{{ aws_region }}"
410 zone: "{{ resource_prefix }}.private"
411 comment: new comment
412 state: present
413 register: output
414 check_mode: true
415
416 - ansible.builtin.assert:
417 that:
418 - output.changed
419
420 - name: Update a private zone comment (new format)
421 amazon.aws.route53_zone:
422 vpcs:
423 - id: "{{ testing_vpc.vpc.id }}"
424 region: "{{ aws_region }}"
425 zone: "{{ resource_prefix }}.private"
426 comment: new comment
427 state: present
428 register: output
429
430 - ansible.builtin.assert:
431 that:
432 - output.changed
433
434 # ============================================================
435 - name: Delete private zone (new format) (CHECK MODE)
436 amazon.aws.route53_zone:
437 vpcs:
438 - id: "{{ testing_vpc.vpc.id }}"
439 region: "{{ aws_region }}"
440 zone: "{{ resource_prefix }}.private"
441 state: absent
442 register: output
443 check_mode: true
444
445 - ansible.builtin.assert:
446 that:
447 - output.changed
448 - "'Successfully deleted' in output.result"
449
450 - name: Delete private zone (new format)
451 amazon.aws.route53_zone:
452 vpcs:
453 - id: "{{ testing_vpc.vpc.id }}"
454 region: "{{ aws_region }}"
455 zone: "{{ resource_prefix }}.private"
456 state: absent
457 register: output
458
459 # ============================================================
460 - block:
461 - name: Create second VPC for use in testing
462 amazon.aws.ec2_vpc_net:
463 name: "{{ resource_prefix }}-vpc2"
464 cidr_block: 10.22.34.0/23
465 tags:
466 Name: Ansible ec2_instance Testing VPC 2
467 tenancy: default
468 register: second_testing_vpc
469
470 - name: Create a private zone with multiple VPCs (CHECK MODE)
471 amazon.aws.route53_zone:
472 vpcs:
473 - id: "{{ testing_vpc.vpc.id }}"
474 region: "{{ aws_region }}"
475 - id: "{{ second_testing_vpc.vpc.id }}"
476 region: "{{ aws_region }}"
477 zone: "{{ resource_prefix }}.private"
478 comment: original comment
479 state: present
480 register: output
481 check_mode: true
482
483 - ansible.builtin.assert:
484 that:
485 - output.changed
486
487 - name: Create a private zone with multiple VPCs
488 amazon.aws.route53_zone:
489 vpcs:
490 - id: "{{ testing_vpc.vpc.id }}"
491 region: "{{ aws_region }}"
492 - id: "{{ second_testing_vpc.vpc.id }}"
493 region: "{{ aws_region }}"
494 zone: "{{ resource_prefix }}.private"
495 comment: original comment
496 state: present
497 register: output
498
499 - ansible.builtin.assert:
500 that:
501 - output.changed
502 - output.vpc_id == testing_vpc.vpc.id # The first one for backwards compatibility
503 - output.vpc_region == aws_region
504 - (output.vpcs | length) == 2
505 - output.vpcs.1.id == second_testing_vpc.vpc.id
506 - output.vpcs.1.region == aws_region
507
508 # ============================================================
509 - name: Delete private zone with multiple VPCs (CHECK MODE)
510 amazon.aws.route53_zone:
511 vpcs:
512 - id: "{{ testing_vpc.vpc.id }}"
513 region: "{{ aws_region }}"
514 - id: "{{ second_testing_vpc.vpc.id }}"
515 region: "{{ aws_region }}"
516 zone: "{{ resource_prefix }}.private"
517 state: absent
518 register: output
519 check_mode: true
520
521 - ansible.builtin.assert:
522 that:
523 - output.changed
524 - "'Successfully deleted' in output.result"
525
526 - name: Delete private zone with multiple VPCs
527 amazon.aws.route53_zone:
528 vpcs:
529 - id: "{{ testing_vpc.vpc.id }}"
530 region: "{{ aws_region }}"
531 - id: "{{ second_testing_vpc.vpc.id }}"
532 region: "{{ aws_region }}"
533 zone: "{{ resource_prefix }}.private"
534 state: absent
535 register: output
536
537 - ansible.builtin.assert:
538 that:
539 - output.changed
540 - "'Successfully deleted' in output.result"
541
542 always:
543 - name: Delete second VPC for use in testing
544 amazon.aws.ec2_vpc_net:
545 name: "{{ resource_prefix }}-vpc2"
546 cidr_block: 10.22.34.0/23
547 state: absent
548
549 # ============================================================
550 - name: Create a public zone
551 amazon.aws.route53_zone:
552 zone: "{{ resource_prefix }}.public2"
553 comment: this is an example
554 state: present
555 register: new_zone
556
557 # Delete zone using its id
558 - name: Delete zone using attribute hosted_zone_id (CHECK MODE)
559 amazon.aws.route53_zone:
560 zone: "{{ resource_prefix }}.public2"
561 hosted_zone_id: "{{ new_zone.zone_id }}"
562 state: absent
563 register: output
564 check_mode: true
565
566 - ansible.builtin.assert:
567 that:
568 - output.changed
569 - "'Successfully deleted' in output.result"
570
571 - name: Delete zone using attribute hosted_zone_id
572 amazon.aws.route53_zone:
573 zone: "{{ resource_prefix }}.public2"
574 hosted_zone_id: "{{ new_zone.zone_id }}"
575 state: absent
576 register: output
577
578 - ansible.builtin.assert:
579 that:
580 - output.changed
581 - "'Successfully deleted' in output.result"
582
583 # ============================================================
584 always:
585 - name: Ensure public zone is deleted
586 amazon.aws.route53_zone:
587 zone: "{{ item }}"
588 state: absent
589 register: removed
590 until: removed is not failed
591 ignore_errors: true
592 retries: 10
593 with_items:
594 - "{{ resource_prefix }}.public"
595 - "{{ resource_prefix }}.public2"
596
597 - name: Ensure private zone is deleted
598 amazon.aws.route53_zone:
599 vpc_id: "{{ testing_vpc.vpc.id }}"
600 vpc_region: "{{ aws_region }}"
601 zone: "{{ resource_prefix }}.private"
602 state: absent
603 register: removed
604 until: removed is not failed
605 ignore_errors: true
606 retries: 10
607
608 - name: Remove the VPC
609 amazon.aws.ec2_vpc_net:
610 name: "{{ resource_prefix }}-vpc"
611 cidr_block: 10.22.32.0/23
612 state: absent
613 register: removed
614 until: removed is not failed
615 ignore_errors: true
616 retries: 10