Debian Codegraph @

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

raw
1 ---
2 - name: Setup AWS Environment
3 module_defaults:
4 group/aws:
5 access_key: "{{ aws_access_key }}"
6 secret_key: "{{ aws_secret_key }}"
7 session_token: "{{ security_token | default(omit) }}"
8 region: "{{ aws_region }}"
9 vars:
10 first_tags:
11 Key with Spaces: Value with spaces
12 CamelCaseKey: CamelCaseValue
13 pascalCaseKey: pascalCaseValue
14 snake_case_key: snake_case_value
15 second_tags:
16 New Key with Spaces: Value with spaces
17 NewCamelCaseKey: CamelCaseValue
18 newPascalCaseKey: pascalCaseValue
19 new_snake_case_key: snake_case_value
20 third_tags:
21 Key with Spaces: Value with spaces
22 CamelCaseKey: CamelCaseValue
23 pascalCaseKey: pascalCaseValue
24 snake_case_key: snake_case_value
25 New Key with Spaces: Updated Value with spaces
26 final_tags:
27 Key with Spaces: Value with spaces
28 CamelCaseKey: CamelCaseValue
29 pascalCaseKey: pascalCaseValue
30 snake_case_key: snake_case_value
31 New Key with Spaces: Updated Value with spaces
32 NewCamelCaseKey: CamelCaseValue
33 newPascalCaseKey: pascalCaseValue
34 new_snake_case_key: snake_case_value
35 name_tags:
36 Name: "{{ vpc_name }}"
37 block:
38 # ============================================================
39
40 - name: Get the current caller identity facts
41 amazon.aws.aws_caller_info:
42 register: caller_facts
43
44 - name: Run the module without parameters
45 amazon.aws.ec2_vpc_net:
46 ignore_errors: true
47 register: result
48
49 - name: Assert failure
50 ansible.builtin.assert:
51 that:
52 - result is failed
53 # - result.msg.startswith("missing required arguments")
54 - result.msg.startswith("one of")
55
56 # ============================================================
57
58 - name: Fetch existing VPC info
59 amazon.aws.ec2_vpc_net_info:
60 filters:
61 tag:Name: "{{ vpc_name }}"
62 register: vpc_info
63
64 - name: Check no-one is using the Prefix before we start
65 ansible.builtin.assert:
66 that:
67 - vpc_info.vpcs | length == 0
68
69 - name: Test check mode creating a VPC
70 amazon.aws.ec2_vpc_net:
71 state: present
72 cidr_block: "{{ vpc_cidr }}"
73 name: "{{ vpc_name }}"
74 check_mode: true
75 register: result
76
77 - name: Get VPC info
78 amazon.aws.ec2_vpc_net_info:
79 filters:
80 tag:Name: "{{ vpc_name }}"
81 register: vpc_info
82
83 - name: Check for a change
84 ansible.builtin.assert:
85 that:
86 - result is changed
87 - vpc_info.vpcs | length == 0
88
89 # ============================================================
90
91 - name: Create a VPC
92 amazon.aws.ec2_vpc_net:
93 state: present
94 cidr_block: "{{ vpc_cidr }}"
95 name: "{{ vpc_name }}"
96 ipv6_cidr: true
97 register: result
98
99 - name: Get VPC info
100 amazon.aws.ec2_vpc_net_info:
101 filters:
102 tag:Name: "{{ vpc_name }}"
103 register: vpc_info
104
105 - name: Assert the VPC was created successfully
106 ansible.builtin.assert:
107 that:
108 - result is successful
109 - result is changed
110 - vpc_info.vpcs | length == 1
111
112 - name: Assert the output
113 ansible.builtin.assert:
114 that:
115 - '"cidr_block" in result.vpc'
116 - result.vpc.cidr_block == vpc_cidr
117 - result.vpc.cidr_block_association_set | length == 1
118 - result.vpc.cidr_block_association_set[0].association_id.startswith("vpc-cidr-assoc-")
119 - result.vpc.cidr_block_association_set[0].cidr_block == vpc_cidr
120 - result.vpc.cidr_block_association_set[0].cidr_block_state.state in ["associated", "associating"]
121 - result.vpc.dhcp_options_id.startswith("dopt-")
122 - result.vpc.id.startswith("vpc-")
123 - '"instance_tenancy" in result.vpc'
124 - result.vpc.ipv6_cidr_block_association_set | length == 1
125 - result.vpc.ipv6_cidr_block_association_set[0].association_id.startswith("vpc-cidr-assoc-")
126 - result.vpc.ipv6_cidr_block_association_set[0].ipv6_cidr_block is defined and result.vpc.ipv6_cidr_block_association_set[0].ipv6_cidr_block is ansible.utils.ipv6
127 - result.vpc.ipv6_cidr_block_association_set[0].ipv6_cidr_block_state.state in ["associated", "associating"]
128 - '"is_default" in result.vpc'
129 - '"state" in result.vpc'
130 - result.vpc.tags.keys() | length == 1
131 - result.vpc.tags.Name == vpc_name
132
133 - name: Set the first VPC's details as facts for comparison and cleanup
134 ansible.builtin.set_fact:
135 vpc_1_result: "{{ result }}"
136 vpc_1: "{{ result.vpc.id }}"
137 vpc_1_ipv6_cidr: "{{ result.vpc.ipv6_cidr_block_association_set.0.ipv6_cidr_block }}"
138 default_dhcp_options_id: "{{ result.vpc.dhcp_options_id }}"
139
140 - name: Create a VPC (retry)
141 amazon.aws.ec2_vpc_net:
142 state: present
143 cidr_block: "{{ vpc_cidr }}"
144 name: "{{ vpc_name }}"
145 ipv6_cidr: true
146 register: result
147
148 - name: Get VPC info
149 amazon.aws.ec2_vpc_net_info:
150 filters:
151 tag:Name: "{{ vpc_name }}"
152 register: vpc_info
153
154 - name: Assert nothing changed
155 ansible.builtin.assert:
156 that:
157 - result is successful
158 - result is not changed
159 - vpc_info.vpcs | length == 1
160 - '"cidr_block" in result.vpc'
161 - result.vpc.cidr_block == vpc_cidr
162 - result.vpc.cidr_block_association_set | length == 1
163 - result.vpc.cidr_block_association_set[0].association_id.startswith("vpc-cidr-assoc-")
164 - result.vpc.cidr_block_association_set[0].cidr_block == vpc_cidr
165 - result.vpc.cidr_block_association_set[0].cidr_block_state.state in ["associated", "associating"]
166 - result.vpc.dhcp_options_id.startswith("dopt-")
167 - result.vpc.id.startswith("vpc-")
168 - '"instance_tenancy" in result.vpc'
169 - result.vpc.ipv6_cidr_block_association_set | length == 1
170 - result.vpc.ipv6_cidr_block_association_set[0].association_id.startswith("vpc-cidr-assoc-")
171 - result.vpc.ipv6_cidr_block_association_set[0].ipv6_cidr_block is defined and result.vpc.ipv6_cidr_block_association_set[0].ipv6_cidr_block is ansible.utils.ipv6
172 - result.vpc.ipv6_cidr_block_association_set[0].ipv6_cidr_block_state.state in ["associated", "associating"]
173 - '"is_default" in result.vpc'
174 - '"state" in result.vpc'
175 - result.vpc.tags.keys() | length == 1
176 - result.vpc.tags.Name == vpc_name
177 - result.vpc.id == vpc_1
178
179 - name: No-op VPC configuration, missing ipv6_cidr property
180 amazon.aws.ec2_vpc_net:
181 state: present
182 cidr_block: "{{ vpc_cidr }}"
183 name: "{{ vpc_name }}"
184 ## Intentionaly commenting out 'ipv6_cidr'
185 ## When the 'ipv6_cidr' property is missing, the VPC should retain its configuration.
186 ## That should not cause the module to set default value 'false' and disassociate the IPv6 block.
187 # ipv6_cidr: True
188 register: result
189
190 - name: Assert configuration did not change
191 ansible.builtin.assert:
192 that:
193 - result is successful
194 - result is not changed
195
196 # ============================================================
197
198 - name: VPC info (no filters)
199 amazon.aws.ec2_vpc_net_info:
200 register: vpc_info
201 retries: 3
202 delay: 3
203 until: '"InvalidVpcID.NotFound" not in ( vpc_info.msg | default("") )'
204
205 - name: Test that our new VPC shows up in the results
206 ansible.builtin.assert:
207 that:
208 - vpc_1 in ( vpc_info.vpcs | map(attribute="vpc_id") | list )
209
210 - name: VPC info (Simple tag filter)
211 amazon.aws.ec2_vpc_net_info:
212 filters:
213 tag:Name: "{{ vpc_name }}"
214 register: vpc_info
215
216 - name: Test vpc_info results
217 ansible.builtin.assert:
218 that:
219 - vpc_info.vpcs[0].cidr_block == vpc_cidr
220 - vpc_info.vpcs[0].cidr_block_association_set | length == 1
221 - vpc_info.vpcs[0].cidr_block_association_set[0].association_id == result.vpc.cidr_block_association_set[0].association_id
222 - vpc_info.vpcs[0].cidr_block_association_set[0].cidr_block == result.vpc.cidr_block_association_set[0].cidr_block
223 - vpc_info.vpcs[0].cidr_block_association_set[0].cidr_block_state.state in ["associated", "associating"]
224 - vpc_info.vpcs[0].dhcp_options_id == result.vpc.dhcp_options_id
225 - ( vpc_info.vpcs[0].enable_dns_hostnames | bool ) == True
226 - ( vpc_info.vpcs[0].enable_dns_support | bool ) == True
227 - vpc_info.vpcs[0].id == result.vpc.id
228 - '"instance_tenancy" in vpc_info.vpcs[0]'
229 - vpc_info.vpcs[0].ipv6_cidr_block_association_set | length == 1
230 - vpc_info.vpcs[0].ipv6_cidr_block_association_set[0].association_id == result.vpc.ipv6_cidr_block_association_set[0].association_id
231 - vpc_info.vpcs[0].ipv6_cidr_block_association_set[0].ipv6_cidr_block == result.vpc.ipv6_cidr_block_association_set[0].ipv6_cidr_block
232 - vpc_info.vpcs[0].ipv6_cidr_block_association_set[0].ipv6_cidr_block_state.state in ["associated", "associating"]
233 - '"is_default" in vpc_info.vpcs[0]'
234 - vpc_info.vpcs[0].owner_id == caller_facts.account
235 - '"state" in vpc_info.vpcs[0]'
236 - vpc_info.vpcs[0].vpc_id == result.vpc.id
237
238 # ============================================================
239
240 - name: Try to add IPv6 CIDR when one already exists
241 amazon.aws.ec2_vpc_net:
242 state: present
243 cidr_block: "{{ vpc_cidr }}"
244 name: "{{ vpc_name }}"
245 ipv6_cidr: true
246 register: result
247
248 - name: Get VPC info
249 amazon.aws.ec2_vpc_net_info:
250 filters:
251 tag:Name: "{{ vpc_name }}"
252 register: vpc_info
253
254 - name: Assert no changes made
255 ansible.builtin.assert:
256 that:
257 - result is not changed
258 - vpc_info.vpcs | length == 1
259
260 # ============================================================
261
262 - name: Test check mode creating an identical VPC (multi_ok)
263 amazon.aws.ec2_vpc_net:
264 state: present
265 cidr_block: "{{ vpc_cidr }}"
266 name: "{{ vpc_name }}"
267 ipv6_cidr: true
268 multi_ok: true
269 check_mode: true
270 register: result
271
272 - name: Get VPC info
273 amazon.aws.ec2_vpc_net_info:
274 filters:
275 tag:Name: "{{ vpc_name }}"
276 register: vpc_info
277
278 - name: Assert a change would be made
279 ansible.builtin.assert:
280 that:
281 - result is changed
282
283 - name: Assert a change was not actually made
284 ansible.builtin.assert:
285 that:
286 - vpc_info.vpcs | length == 1
287
288 # ============================================================
289
290 - name: Create a VPC with a dedicated tenancy using the same CIDR and name
291 amazon.aws.ec2_vpc_net:
292 state: present
293 cidr_block: "{{ vpc_cidr }}"
294 name: "{{ vpc_name }}"
295 ipv6_cidr: true
296 tenancy: dedicated
297 multi_ok: true
298 register: result
299
300 - name: Get VPC info
301 amazon.aws.ec2_vpc_net_info:
302 filters:
303 tag:Name: "{{ vpc_name }}"
304 register: vpc_info
305
306 - name: Assert a new VPC was created
307 ansible.builtin.assert:
308 that:
309 - result is successful
310 - result is changed
311 - result.vpc.instance_tenancy == "dedicated"
312 - result.vpc.id != vpc_1
313 - vpc_info.vpcs | length == 2
314
315 - name: Set the second VPC's details as facts for comparison and cleanup
316 ansible.builtin.set_fact:
317 vpc_2_result: "{{ result }}"
318 vpc_2: "{{ result.vpc.id }}"
319
320 # ============================================================
321
322 - name: VPC info (Simple VPC-ID filter)
323 amazon.aws.ec2_vpc_net_info:
324 filters:
325 vpc-id: "{{ vpc_2 }}"
326 register: vpc_info
327
328 - name: Test vpc_info results
329 ansible.builtin.assert:
330 that:
331 - vpc_info.vpcs[0].cidr_block == vpc_cidr
332 - vpc_info.vpcs[0].cidr_block_association_set | length == 1
333 - vpc_info.vpcs[0].cidr_block_association_set[0].association_id == result.vpc.cidr_block_association_set[0].association_id
334 - vpc_info.vpcs[0].cidr_block_association_set[0].cidr_block == result.vpc.cidr_block_association_set[0].cidr_block
335 - vpc_info.vpcs[0].cidr_block_association_set[0].cidr_block_state.state in ["associated", "associating"]
336 - vpc_info.vpcs[0].dhcp_options_id == result.vpc.dhcp_options_id
337 - ( vpc_info.vpcs[0].enable_dns_hostnames | bool ) == True
338 - ( vpc_info.vpcs[0].enable_dns_support | bool ) == True
339 - vpc_info.vpcs[0].id == vpc_2
340 - '"instance_tenancy" in vpc_info.vpcs[0]'
341 - vpc_info.vpcs[0].ipv6_cidr_block_association_set | length == 1
342 - vpc_info.vpcs[0].ipv6_cidr_block_association_set[0].association_id == result.vpc.ipv6_cidr_block_association_set[0].association_id
343 - vpc_info.vpcs[0].ipv6_cidr_block_association_set[0].ipv6_cidr_block == result.vpc.ipv6_cidr_block_association_set[0].ipv6_cidr_block
344 - vpc_info.vpcs[0].ipv6_cidr_block_association_set[0].ipv6_cidr_block_state.state in ["associated", "associating"]
345 - '"is_default" in vpc_info.vpcs[0]'
346 - vpc_info.vpcs[0].owner_id == caller_facts.account
347 - '"state" in vpc_info.vpcs[0]'
348 - vpc_info.vpcs[0].vpc_id == vpc_2
349
350 # ============================================================
351
352 # This will only fail if there are already *2* vpcs otherwise ec2_vpc_net
353 # assumes you want to update your existing VPC...
354 - name: Attempt to create another VPC with the same CIDR and name without multi_ok
355 amazon.aws.ec2_vpc_net:
356 state: present
357 cidr_block: "{{ vpc_cidr }}"
358 name: "{{ vpc_name }}"
359 ipv6_cidr: true
360 tenancy: dedicated
361 multi_ok: false
362 register: new_result
363 ignore_errors: true
364
365 - name: Get VPC info
366 amazon.aws.ec2_vpc_net_info:
367 filters:
368 tag:Name: "{{ vpc_name }}"
369 register: vpc_info
370
371 - name: Assert failure
372 ansible.builtin.assert:
373 that:
374 - new_result is failed
375 - '"If you would like to create the VPC anyway please pass True to the multi_ok param" in new_result.msg'
376 - vpc_info.vpcs | length == 2
377
378 # ============================================================
379
380 - name: Set new name for second VPC
381 amazon.aws.ec2_vpc_net:
382 state: present
383 vpc_id: "{{ vpc_2 }}"
384 name: "{{ vpc_name_updated }}"
385 cidr_block: "{{ vpc_cidr }}"
386 register: result
387
388 - name: Assert name changed
389 ansible.builtin.assert:
390 that:
391 - '"cidr_block" in result.vpc'
392 - result.vpc.cidr_block == vpc_cidr
393 - result.vpc.cidr_block_association_set | length == 1
394 - result.vpc.cidr_block_association_set[0].association_id.startswith("vpc-cidr-assoc-")
395 - result.vpc.cidr_block_association_set[0].cidr_block == vpc_cidr
396 - result.vpc.cidr_block_association_set[0].cidr_block_state.state in ["associated", "associating"]
397 - result.vpc.dhcp_options_id.startswith("dopt-")
398 - '"instance_tenancy" in result.vpc'
399 - result.vpc.ipv6_cidr_block_association_set | length == 1
400 - result.vpc.ipv6_cidr_block_association_set[0].association_id.startswith("vpc-cidr-assoc-")
401 - result.vpc.ipv6_cidr_block_association_set[0].ipv6_cidr_block is defined and result.vpc.ipv6_cidr_block_association_set[0].ipv6_cidr_block is ansible.utils.ipv6
402 - result.vpc.ipv6_cidr_block_association_set[0].ipv6_cidr_block_state.state in ["associated", "associating"]
403 - '"is_default" in result.vpc'
404 - '"state" in result.vpc'
405 - result.vpc.tags.keys() | length == 1
406 - result.vpc.tags.Name == vpc_name_updated
407 - result.vpc.id == vpc_2
408
409 - name: Get VPC info
410 amazon.aws.ec2_vpc_net_info:
411 filters:
412 tag:Name: "{{ vpc_name }}"
413 register: vpc_info
414
415 - name: Assert success
416 ansible.builtin.assert:
417 that:
418 - result is changed
419 - vpc_info.vpcs | length == 1
420 - vpc_info.vpcs[0].vpc_id == vpc_1
421
422 - name: Get VPC info
423 amazon.aws.ec2_vpc_net_info:
424 filters:
425 tag:Name: "{{ vpc_name_updated }}"
426 register: vpc_info
427
428 - name: Assert success
429 ansible.builtin.assert:
430 that:
431 - result is changed
432 - vpc_info.vpcs | length == 1
433 - vpc_info.vpcs[0].vpc_id == vpc_2
434
435 - name: Delete second VPC (by id)
436 amazon.aws.ec2_vpc_net:
437 vpc_id: "{{ vpc_2 }}"
438 state: absent
439 cidr_block: "{{ vpc_cidr }}"
440 register: result
441
442 # ============================================================
443
444 - name: Attempt to delete a VPC that doesn't exist
445 amazon.aws.ec2_vpc_net:
446 state: absent
447 cidr_block: "{{ vpc_cidr }}"
448 name: "{{ vpc_name }}-does-not-exist"
449 register: result
450
451 - name: Assert no changes were made
452 ansible.builtin.assert:
453 that:
454 - result is not changed
455 - not result.vpc
456
457 # ============================================================
458
459 - name: Create a DHCP option set to use in next test
460 amazon.aws.ec2_vpc_dhcp_option:
461 dns_servers:
462 - 8.8.4.4
463 - 8.8.8.8
464 tags:
465 Name: "{{ vpc_name }}"
466 register: new_dhcp
467
468 - name: Assert the DHCP option set was successfully created
469 ansible.builtin.assert:
470 that:
471 - new_dhcp is successful
472
473 - name: Modify the DHCP options set for a VPC (check_mode)
474 amazon.aws.ec2_vpc_net:
475 state: present
476 cidr_block: "{{ vpc_cidr }}"
477 name: "{{ vpc_name }}"
478 dhcp_opts_id: "{{ new_dhcp.dhcp_options_id }}"
479 register: result
480 check_mode: true
481
482 - name: Get VPC info
483 amazon.aws.ec2_vpc_net_info:
484 filters:
485 tag:Name: "{{ vpc_name }}"
486 register: vpc_info
487
488 - name: Assert the DHCP option set changed but didn't update
489 ansible.builtin.assert:
490 that:
491 - result is changed
492 - result.vpc.id == vpc_1
493 - vpc_info.vpcs | length == 1
494 - vpc_info.vpcs[0].dhcp_options_id == default_dhcp_options_id
495
496 - name: Modify the DHCP options set for a VPC
497 amazon.aws.ec2_vpc_net:
498 state: present
499 cidr_block: "{{ vpc_cidr }}"
500 name: "{{ vpc_name }}"
501 dhcp_opts_id: "{{ new_dhcp.dhcp_options_id }}"
502 register: result
503
504 - name: Get VPC info
505 amazon.aws.ec2_vpc_net_info:
506 filters:
507 tag:Name: "{{ vpc_name }}"
508 register: vpc_info
509
510 - name: Assert the DHCP option set changed
511 ansible.builtin.assert:
512 that:
513 - result is changed
514 - result.vpc.id == vpc_1
515 - default_dhcp_options_id != result.vpc.dhcp_options_id
516 - result.vpc.dhcp_options_id == new_dhcp.dhcp_options_id
517 - vpc_info.vpcs | length == 1
518 - vpc_info.vpcs[0].dhcp_options_id == new_dhcp.dhcp_options_id
519
520 - name: Modify the DHCP options set for a VPC (retry)
521 amazon.aws.ec2_vpc_net:
522 state: present
523 cidr_block: "{{ vpc_cidr }}"
524 name: "{{ vpc_name }}"
525 dhcp_opts_id: "{{ new_dhcp.dhcp_options_id }}"
526 register: result
527
528 - name: Get VPC info
529 amazon.aws.ec2_vpc_net_info:
530 filters:
531 tag:Name: "{{ vpc_name }}"
532 register: vpc_info
533
534 - name: Assert the DHCP option set changed
535 ansible.builtin.assert:
536 that:
537 - result is not changed
538 - result.vpc.id == vpc_1
539 - result.vpc.dhcp_options_id == new_dhcp.dhcp_options_id
540 - vpc_info.vpcs | length == 1
541 - vpc_info.vpcs[0].dhcp_options_id == new_dhcp.dhcp_options_id
542
543 # ============================================================
544
545 - name: Disable dns_hostnames (check mode)
546 amazon.aws.ec2_vpc_net:
547 state: present
548 cidr_block: "{{ vpc_cidr }}"
549 name: "{{ vpc_name }}"
550 dns_hostnames: false
551 register: result
552 check_mode: true
553
554 - name: Get VPC info
555 amazon.aws.ec2_vpc_net_info:
556 filters:
557 tag:Name: "{{ vpc_name }}"
558 register: vpc_info
559
560 - name: Assert changed was set but not made
561 ansible.builtin.assert:
562 that:
563 - result is successful
564 - result is changed
565 - vpc_info.vpcs | length == 1
566 - vpc_info.vpcs[0].enable_dns_hostnames | bool == True
567 - vpc_info.vpcs[0].enable_dns_support | bool == True
568
569 - name: Disable dns_hostnames
570 amazon.aws.ec2_vpc_net:
571 state: present
572 cidr_block: "{{ vpc_cidr }}"
573 name: "{{ vpc_name }}"
574 dns_hostnames: false
575 register: result
576
577 - name: Get VPC info
578 amazon.aws.ec2_vpc_net_info:
579 filters:
580 tag:Name: "{{ vpc_name }}"
581 register: vpc_info
582
583 - name: Assert a change was made
584 ansible.builtin.assert:
585 that:
586 - result is successful
587 - result is changed
588 - result.vpc.id == vpc_1
589 - vpc_info.vpcs | length == 1
590 - vpc_info.vpcs[0].enable_dns_hostnames | bool == False
591 - vpc_info.vpcs[0].enable_dns_support | bool == True
592
593 - name: Disable dns_hostnames (retry)
594 amazon.aws.ec2_vpc_net:
595 state: present
596 cidr_block: "{{ vpc_cidr }}"
597 name: "{{ vpc_name }}"
598 dns_hostnames: false
599 register: result
600
601 - name: Get VPC info
602 amazon.aws.ec2_vpc_net_info:
603 filters:
604 tag:Name: "{{ vpc_name }}"
605 register: vpc_info
606
607 - name: Assert a change was made
608 ansible.builtin.assert:
609 that:
610 - result is successful
611 - result is not changed
612 - result.vpc.id == vpc_1
613 - vpc_info.vpcs | length == 1
614 - vpc_info.vpcs[0].enable_dns_hostnames | bool == False
615 - vpc_info.vpcs[0].enable_dns_support | bool == True
616
617 - name: Disable dns_support (check mode)
618 amazon.aws.ec2_vpc_net:
619 state: present
620 cidr_block: "{{ vpc_cidr }}"
621 name: "{{ vpc_name }}"
622 dns_hostnames: false
623 dns_support: false
624 check_mode: true
625 register: result
626
627 - name: Get VPC info
628 amazon.aws.ec2_vpc_net_info:
629 filters:
630 tag:Name: "{{ vpc_name }}"
631 register: vpc_info
632
633 - name: Assert changed was set but not made
634 ansible.builtin.assert:
635 that:
636 - result is successful
637 - result is changed
638 - result.vpc.id == vpc_1
639 - vpc_info.vpcs | length == 1
640 - vpc_info.vpcs[0].enable_dns_hostnames | bool == False
641 - vpc_info.vpcs[0].enable_dns_support | bool == True
642
643 - name: Disable dns_support
644 amazon.aws.ec2_vpc_net:
645 state: present
646 cidr_block: "{{ vpc_cidr }}"
647 name: "{{ vpc_name }}"
648 dns_hostnames: false
649 dns_support: false
650 register: result
651
652 - name: Get VPC info
653 amazon.aws.ec2_vpc_net_info:
654 filters:
655 tag:Name: "{{ vpc_name }}"
656 register: vpc_info
657
658 - name: Assert a change was made
659 ansible.builtin.assert:
660 that:
661 - result is successful
662 - result is changed
663 - result.vpc.id == vpc_1
664 - vpc_info.vpcs | length == 1
665 - vpc_info.vpcs[0].enable_dns_hostnames | bool == False
666 - vpc_info.vpcs[0].enable_dns_support | bool == False
667
668 - name: Disable dns_support (retry)
669 amazon.aws.ec2_vpc_net:
670 state: present
671 cidr_block: "{{ vpc_cidr }}"
672 name: "{{ vpc_name }}"
673 dns_hostnames: false
674 dns_support: false
675 register: result
676
677 - name: Get VPC info
678 amazon.aws.ec2_vpc_net_info:
679 filters:
680 tag:Name: "{{ vpc_name }}"
681 register: vpc_info
682
683 - name: Assert a change was not made
684 ansible.builtin.assert:
685 that:
686 - result is successful
687 - result is not changed
688 - result.vpc.id == vpc_1
689 - vpc_info.vpcs | length == 1
690 - vpc_info.vpcs[0].enable_dns_hostnames | bool == False
691 - vpc_info.vpcs[0].enable_dns_support | bool == False
692
693 - name: Re-enable dns_support (check mode)
694 amazon.aws.ec2_vpc_net:
695 state: present
696 cidr_block: "{{ vpc_cidr }}"
697 name: "{{ vpc_name }}"
698 dns_hostnames: true
699 dns_support: true
700 register: result
701 check_mode: true
702
703 - name: Get VPC info
704 amazon.aws.ec2_vpc_net_info:
705 filters:
706 tag:Name: "{{ vpc_name }}"
707 register: vpc_info
708
709 - name: Assert a change would be made but has not been
710 ansible.builtin.assert:
711 that:
712 - result is successful
713 - result is changed
714 - result.vpc.id == vpc_1
715 - vpc_info.vpcs | length == 1
716 - vpc_info.vpcs[0].enable_dns_hostnames | bool == False
717 - vpc_info.vpcs[0].enable_dns_support | bool == False
718
719 - name: Re-enable dns_support
720 amazon.aws.ec2_vpc_net:
721 state: present
722 cidr_block: "{{ vpc_cidr }}"
723 name: "{{ vpc_name }}"
724 dns_hostnames: true
725 dns_support: true
726 register: result
727
728 - name: Get VPC info
729 amazon.aws.ec2_vpc_net_info:
730 filters:
731 tag:Name: "{{ vpc_name }}"
732 register: vpc_info
733
734 - name: Assert a change was made
735 ansible.builtin.assert:
736 that:
737 - result is successful
738 - result is changed
739 - result.vpc.id == vpc_1
740 - vpc_info.vpcs | length == 1
741 - vpc_info.vpcs[0].enable_dns_hostnames | bool == True
742 - vpc_info.vpcs[0].enable_dns_support | bool == True
743
744 - name: Re-enable dns_support (retry)
745 amazon.aws.ec2_vpc_net:
746 state: present
747 cidr_block: "{{ vpc_cidr }}"
748 name: "{{ vpc_name }}"
749 dns_hostnames: true
750 dns_support: true
751 register: result
752
753 - name: Get VPC info
754 amazon.aws.ec2_vpc_net_info:
755 filters:
756 tag:Name: "{{ vpc_name }}"
757 register: vpc_info
758
759 - name: Assert a change was not made
760 ansible.builtin.assert:
761 that:
762 - result is successful
763 - result is not changed
764 - result.vpc.id == vpc_1
765 - vpc_info.vpcs | length == 1
766 - vpc_info.vpcs[0].enable_dns_hostnames | bool == True
767 - vpc_info.vpcs[0].enable_dns_support | bool == True
768
769 # ============================================================
770
771 - name: Add tags (check mode)
772 amazon.aws.ec2_vpc_net:
773 state: present
774 cidr_block: "{{ vpc_cidr }}"
775 name: "{{ vpc_name }}"
776 tags: "{{ first_tags }}"
777 check_mode: true
778 register: result
779
780 - name: Get VPC info
781 amazon.aws.ec2_vpc_net_info:
782 filters:
783 tag:Name: "{{ vpc_name }}"
784 register: vpc_info
785
786 - name: Assert the VPC has Name but not Ansible tag
787 ansible.builtin.assert:
788 that:
789 - result is successful
790 - result is changed
791 - result.vpc.id == vpc_1
792 - result.vpc.tags | length == 1
793 - result.vpc.tags.Name == vpc_name
794 - vpc_info.vpcs | length == 1
795 - vpc_info.vpcs[0].tags == name_tags
796
797 - name: Add tags
798 amazon.aws.ec2_vpc_net:
799 state: present
800 cidr_block: "{{ vpc_cidr }}"
801 name: "{{ vpc_name }}"
802 tags: "{{ first_tags }}"
803 register: result
804
805 - name: Get VPC info
806 amazon.aws.ec2_vpc_net_info:
807 filters:
808 tag:Name: "{{ vpc_name }}"
809 register: vpc_info
810
811 - name: Assert the VPC has Name and Ansible tags
812 ansible.builtin.assert:
813 that:
814 - result is successful
815 - result is changed
816 - result.vpc.id == vpc_1
817 - result.vpc.tags == (first_tags | combine(name_tags))
818 - vpc_info.vpcs | length == 1
819 - vpc_info.vpcs[0].tags == (first_tags | combine(name_tags))
820
821 - name: Add tags (no change)
822 amazon.aws.ec2_vpc_net:
823 state: present
824 cidr_block: "{{ vpc_cidr }}"
825 name: "{{ vpc_name }}"
826 tags: "{{ first_tags }}"
827 register: result
828
829 - name: Get VPC info
830 amazon.aws.ec2_vpc_net_info:
831 filters:
832 tag:Name: "{{ vpc_name }}"
833 register: vpc_info
834
835 - name: Assert the VPC has Name and Ansible tags
836 ansible.builtin.assert:
837 that:
838 - result is successful
839 - result is not changed
840 - result.vpc.id == vpc_1
841 - result.vpc.tags == (first_tags | combine(name_tags))
842 - vpc_info.vpcs | length == 1
843 - vpc_info.vpcs[0].tags == (first_tags | combine(name_tags))
844
845 # ============================================================
846
847 - name: Modify tags with purge (check mode)
848 amazon.aws.ec2_vpc_net:
849 state: present
850 cidr_block: "{{ vpc_cidr }}"
851 name: "{{ vpc_name }}"
852 tags: "{{ second_tags }}"
853 purge_tags: true
854 check_mode: true
855 register: result
856
857 - name: Get VPC info
858 amazon.aws.ec2_vpc_net_info:
859 filters:
860 tag:Name: "{{ vpc_name }}"
861 register: vpc_info
862
863 - name: Assert the VPC has Name but not Ansible tag
864 ansible.builtin.assert:
865 that:
866 - result is successful
867 - result is changed
868 - result.vpc.id == vpc_1
869 - result.vpc.tags == (first_tags | combine(name_tags))
870 - vpc_info.vpcs | length == 1
871 - vpc_info.vpcs[0].tags == (first_tags | combine(name_tags))
872
873 - name: Modify tags with purge
874 amazon.aws.ec2_vpc_net:
875 state: present
876 cidr_block: "{{ vpc_cidr }}"
877 name: "{{ vpc_name }}"
878 tags: "{{ second_tags }}"
879 purge_tags: true
880 register: result
881
882 - name: Get VPC info
883 amazon.aws.ec2_vpc_net_info:
884 filters:
885 tag:Name: "{{ vpc_name }}"
886 register: vpc_info
887
888 - name: Assert the VPC has Name and Ansible tags
889 ansible.builtin.assert:
890 that:
891 - result is successful
892 - result is changed
893 - result.vpc.id == vpc_1
894 - result.vpc.tags == (second_tags | combine(name_tags))
895 - vpc_info.vpcs | length == 1
896 - vpc_info.vpcs[0].tags == (second_tags | combine(name_tags))
897
898 - name: Modify tags with purge (no change)
899 amazon.aws.ec2_vpc_net:
900 state: present
901 cidr_block: "{{ vpc_cidr }}"
902 name: "{{ vpc_name }}"
903 tags: "{{ second_tags }}"
904 purge_tags: true
905 register: result
906
907 - name: Get VPC info
908 amazon.aws.ec2_vpc_net_info:
909 filters:
910 tag:Name: "{{ vpc_name }}"
911 register: vpc_info
912
913 - name: Assert the VPC has Name and Ansible tags
914 ansible.builtin.assert:
915 that:
916 - result is successful
917 - result is not changed
918 - result.vpc.id == vpc_1
919 - result.vpc.tags == (second_tags | combine(name_tags))
920 - vpc_info.vpcs | length == 1
921 - vpc_info.vpcs[0].tags == (second_tags | combine(name_tags))
922
923 # ============================================================
924
925 - name: Modify tags without purge (check mode)
926 amazon.aws.ec2_vpc_net:
927 state: present
928 cidr_block: "{{ vpc_cidr }}"
929 name: "{{ vpc_name }}"
930 tags: "{{ third_tags }}"
931 purge_tags: false
932 check_mode: true
933 register: result
934
935 - name: Get VPC info
936 amazon.aws.ec2_vpc_net_info:
937 filters:
938 tag:Name: "{{ vpc_name }}"
939 register: vpc_info
940
941 - name: Assert the VPC has Name but not Ansible tag
942 ansible.builtin.assert:
943 that:
944 - result is successful
945 - result is changed
946 - result.vpc.id == vpc_1
947 - result.vpc.tags == (second_tags | combine(name_tags))
948 - vpc_info.vpcs | length == 1
949 - vpc_info.vpcs[0].tags == (second_tags | combine(name_tags))
950
951 - name: Modify tags with purge
952 amazon.aws.ec2_vpc_net:
953 state: present
954 cidr_block: "{{ vpc_cidr }}"
955 name: "{{ vpc_name }}"
956 tags: "{{ third_tags }}"
957 purge_tags: false
958 register: result
959
960 - name: Get VPC info
961 amazon.aws.ec2_vpc_net_info:
962 filters:
963 tag:Name: "{{ vpc_name }}"
964 register: vpc_info
965
966 - name: Assert the VPC has Name and Ansible tags
967 ansible.builtin.assert:
968 that:
969 - result is successful
970 - result is changed
971 - result.vpc.id == vpc_1
972 - result.vpc.tags == (final_tags | combine(name_tags))
973 - vpc_info.vpcs | length == 1
974 - vpc_info.vpcs[0].tags == (final_tags | combine(name_tags))
975
976 - name: Modify tags with purge (no change)
977 amazon.aws.ec2_vpc_net:
978 state: present
979 cidr_block: "{{ vpc_cidr }}"
980 name: "{{ vpc_name }}"
981 tags: "{{ third_tags }}"
982 purge_tags: false
983 register: result
984
985 - name: Get VPC info
986 amazon.aws.ec2_vpc_net_info:
987 filters:
988 tag:Name: "{{ vpc_name }}"
989 register: vpc_info
990
991 - name: Assert the VPC has Name and Ansible tags
992 ansible.builtin.assert:
993 that:
994 - result is successful
995 - result is not changed
996 - result.vpc.id == vpc_1
997 - result.vpc.tags == (final_tags | combine(name_tags))
998 - vpc_info.vpcs | length == 1
999 - vpc_info.vpcs[0].tags == (final_tags | combine(name_tags))
1000
1001 # ============================================================
1002
1003 - name: Modify CIDR (check mode)
1004 amazon.aws.ec2_vpc_net:
1005 state: present
1006 cidr_block:
1007 - "{{ vpc_cidr }}"
1008 - "{{ vpc_cidr_a }}"
1009 name: "{{ vpc_name }}"
1010 check_mode: true
1011 register: result
1012
1013 - name: Get VPC info
1014 amazon.aws.ec2_vpc_net_info:
1015 filters:
1016 tag:Name: "{{ vpc_name }}"
1017 register: vpc_info
1018
1019 - name: Check the CIDRs weren't changed
1020 ansible.builtin.assert:
1021 that:
1022 - result is successful
1023 - result is changed
1024 - result.vpc.id == vpc_1
1025 - vpc_info.vpcs | length == 1
1026 - vpc_info.vpcs[0].cidr_block == vpc_cidr
1027 - vpc_cidr in (result.vpc.cidr_block_association_set | map(attribute="cidr_block") | list)
1028 - vpc_cidr_a not in (result.vpc.cidr_block_association_set | map(attribute="cidr_block") | list)
1029 - vpc_cidr_b not in (result.vpc.cidr_block_association_set | map(attribute="cidr_block") | list)
1030 - vpc_info.vpcs[0].cidr_block_association_set | length == 1
1031 - vpc_info.vpcs[0].cidr_block_association_set[0].association_id.startswith("vpc-cidr-assoc-")
1032 - vpc_info.vpcs[0].cidr_block_association_set[0].cidr_block_state.state in ["associated", "associating"]
1033 - vpc_cidr in (vpc_info.vpcs[0].cidr_block_association_set | map(attribute="cidr_block") | list)
1034 - vpc_cidr_a not in (vpc_info.vpcs[0].cidr_block_association_set | map(attribute="cidr_block") | list)
1035 - vpc_cidr_b not in (result.vpc.cidr_block_association_set | map(attribute="cidr_block") | list)
1036
1037 - name: Modify CIDR
1038 amazon.aws.ec2_vpc_net:
1039 state: present
1040 cidr_block:
1041 - "{{ vpc_cidr }}"
1042 - "{{ vpc_cidr_a }}"
1043 name: "{{ vpc_name }}"
1044 register: result
1045
1046 - name: Get VPC info
1047 amazon.aws.ec2_vpc_net_info:
1048 filters:
1049 tag:Name: "{{ vpc_name }}"
1050 register: vpc_info
1051
1052 - name: Assert the CIDRs changed
1053 ansible.builtin.assert:
1054 that:
1055 - result is successful
1056 - result is changed
1057 - result.vpc.id == vpc_1
1058 - vpc_info.vpcs | length == 1
1059 - result.vpc.cidr_block == vpc_cidr
1060 - vpc_info.vpcs[0].cidr_block == vpc_cidr
1061 - result.vpc.cidr_block_association_set | length == 2
1062 - result.vpc.cidr_block_association_set[0].association_id.startswith("vpc-cidr-assoc-")
1063 - result.vpc.cidr_block_association_set[1].association_id.startswith("vpc-cidr-assoc-")
1064 - result.vpc.cidr_block_association_set[0].cidr_block_state.state in ["associated", "associating"]
1065 - result.vpc.cidr_block_association_set[1].cidr_block_state.state in ["associated", "associating"]
1066 - vpc_cidr in (result.vpc.cidr_block_association_set | map(attribute="cidr_block") | list)
1067 - vpc_cidr_a in (result.vpc.cidr_block_association_set | map(attribute="cidr_block") | list)
1068 - vpc_cidr_b not in (result.vpc.cidr_block_association_set | map(attribute="cidr_block") | list)
1069 - vpc_info.vpcs[0].cidr_block_association_set | length == 2
1070 - vpc_info.vpcs[0].cidr_block_association_set[0].association_id.startswith("vpc-cidr-assoc-")
1071 - vpc_info.vpcs[0].cidr_block_association_set[1].association_id.startswith("vpc-cidr-assoc-")
1072 - vpc_info.vpcs[0].cidr_block_association_set[0].cidr_block_state.state in ["associated", "associating"]
1073 - vpc_info.vpcs[0].cidr_block_association_set[1].cidr_block_state.state in ["associated", "associating"]
1074 - vpc_cidr in (vpc_info.vpcs[0].cidr_block_association_set | map(attribute="cidr_block") | list)
1075 - vpc_cidr_a in (vpc_info.vpcs[0].cidr_block_association_set | map(attribute="cidr_block") | list)
1076 - vpc_cidr_b not in (vpc_info.vpcs[0].cidr_block_association_set | map(attribute="cidr_block") | list)
1077
1078 - name: Modify CIDR (no change)
1079 amazon.aws.ec2_vpc_net:
1080 state: present
1081 cidr_block:
1082 - "{{ vpc_cidr }}"
1083 - "{{ vpc_cidr_a }}"
1084 name: "{{ vpc_name }}"
1085 register: result
1086
1087 - name: Get VPC info
1088 amazon.aws.ec2_vpc_net_info:
1089 filters:
1090 tag:Name: "{{ vpc_name }}"
1091 register: vpc_info
1092
1093 - name: Assert the CIDRs didn't change
1094 ansible.builtin.assert:
1095 that:
1096 - result is successful
1097 - result is not changed
1098 - result.vpc.id == vpc_1
1099 - vpc_info.vpcs | length == 1
1100 - result.vpc.cidr_block == vpc_cidr
1101 - vpc_info.vpcs[0].cidr_block == vpc_cidr
1102 - result.vpc.cidr_block_association_set | length == 2
1103 - result.vpc.cidr_block_association_set[0].association_id.startswith("vpc-cidr-assoc-")
1104 - result.vpc.cidr_block_association_set[1].association_id.startswith("vpc-cidr-assoc-")
1105 - result.vpc.cidr_block_association_set[0].cidr_block_state.state in ["associated", "associating"]
1106 - result.vpc.cidr_block_association_set[1].cidr_block_state.state in ["associated", "associating"]
1107 - vpc_cidr in (result.vpc.cidr_block_association_set | map(attribute="cidr_block") | list)
1108 - vpc_cidr_a in (result.vpc.cidr_block_association_set | map(attribute="cidr_block") | list)
1109 - vpc_cidr_b not in (result.vpc.cidr_block_association_set | map(attribute="cidr_block") | list)
1110 - vpc_info.vpcs[0].cidr_block_association_set | length == 2
1111 - vpc_info.vpcs[0].cidr_block_association_set[0].association_id.startswith("vpc-cidr-assoc-")
1112 - vpc_info.vpcs[0].cidr_block_association_set[1].association_id.startswith("vpc-cidr-assoc-")
1113 - vpc_info.vpcs[0].cidr_block_association_set[0].cidr_block_state.state in ["associated", "associating"]
1114 - vpc_info.vpcs[0].cidr_block_association_set[1].cidr_block_state.state in ["associated", "associating"]
1115 - vpc_cidr in (vpc_info.vpcs[0].cidr_block_association_set | map(attribute="cidr_block") | list)
1116 - vpc_cidr_a in (vpc_info.vpcs[0].cidr_block_association_set | map(attribute="cidr_block") | list)
1117 - vpc_cidr_b not in (vpc_info.vpcs[0].cidr_block_association_set | map(attribute="cidr_block") | list)
1118
1119 - name: Modify CIDR - no purge (check mode)
1120 amazon.aws.ec2_vpc_net:
1121 state: present
1122 cidr_block:
1123 - "{{ vpc_cidr }}"
1124 - "{{ vpc_cidr_b }}"
1125 name: "{{ vpc_name }}"
1126 check_mode: true
1127 register: result
1128
1129 - name: Get VPC info
1130 amazon.aws.ec2_vpc_net_info:
1131 filters:
1132 tag:Name: "{{ vpc_name }}"
1133 register: vpc_info
1134
1135 - name: Check the CIDRs weren't changed
1136 ansible.builtin.assert:
1137 that:
1138 - result is successful
1139 - result is changed
1140 - vpc_info.vpcs | length == 1
1141 - vpc_info.vpcs[0].cidr_block == vpc_cidr
1142 - vpc_cidr in (result.vpc.cidr_block_association_set | map(attribute="cidr_block") | list)
1143 - vpc_cidr_a in (result.vpc.cidr_block_association_set | map(attribute="cidr_block") | list)
1144 - vpc_cidr_b not in (result.vpc.cidr_block_association_set | map(attribute="cidr_block") | list)
1145 - vpc_info.vpcs[0].cidr_block_association_set | length == 2
1146 - vpc_info.vpcs[0].cidr_block_association_set[0].association_id.startswith("vpc-cidr-assoc-")
1147 - vpc_info.vpcs[0].cidr_block_association_set[1].association_id.startswith("vpc-cidr-assoc-")
1148 - vpc_info.vpcs[0].cidr_block_association_set[0].cidr_block_state.state in ["associated", "associating"]
1149 - vpc_info.vpcs[0].cidr_block_association_set[1].cidr_block_state.state in ["associated", "associating"]
1150 - vpc_cidr in (vpc_info.vpcs[0].cidr_block_association_set | map(attribute="cidr_block") | list)
1151 - vpc_cidr_a in (vpc_info.vpcs[0].cidr_block_association_set | map(attribute="cidr_block") | list)
1152 - vpc_cidr_b not in (vpc_info.vpcs[0].cidr_block_association_set | map(attribute="cidr_block") | list)
1153
1154 - name: Modify CIDR - no purge
1155 amazon.aws.ec2_vpc_net:
1156 state: present
1157 cidr_block:
1158 - "{{ vpc_cidr }}"
1159 - "{{ vpc_cidr_b }}"
1160 name: "{{ vpc_name }}"
1161 register: result
1162
1163 - name: Get VPC info
1164 amazon.aws.ec2_vpc_net_info:
1165 filters:
1166 tag:Name: "{{ vpc_name }}"
1167 register: vpc_info
1168
1169 - name: Assert the CIDRs changed
1170 ansible.builtin.assert:
1171 that:
1172 - result is successful
1173 - result is changed
1174 - result.vpc.id == vpc_1
1175 - vpc_info.vpcs | length == 1
1176 - result.vpc.cidr_block == vpc_cidr
1177 - vpc_info.vpcs[0].cidr_block == vpc_cidr
1178 - result.vpc.cidr_block_association_set | length == 3
1179 - result.vpc.cidr_block_association_set[0].association_id.startswith("vpc-cidr-assoc-")
1180 - result.vpc.cidr_block_association_set[1].association_id.startswith("vpc-cidr-assoc-")
1181 - result.vpc.cidr_block_association_set[2].association_id.startswith("vpc-cidr-assoc-")
1182 - result.vpc.cidr_block_association_set[0].cidr_block_state.state in ["associated", "associating"]
1183 - result.vpc.cidr_block_association_set[1].cidr_block_state.state in ["associated", "associating"]
1184 - result.vpc.cidr_block_association_set[2].cidr_block_state.state in ["associated", "associating"]
1185 - vpc_cidr in (result.vpc.cidr_block_association_set | map(attribute="cidr_block") | list)
1186 - vpc_cidr_a in (result.vpc.cidr_block_association_set | map(attribute="cidr_block") | list)
1187 - vpc_cidr_b in (result.vpc.cidr_block_association_set | map(attribute="cidr_block") | list)
1188 - vpc_info.vpcs[0].cidr_block_association_set | length == 3
1189 - vpc_info.vpcs[0].cidr_block_association_set[0].association_id.startswith("vpc-cidr-assoc-")
1190 - vpc_info.vpcs[0].cidr_block_association_set[1].association_id.startswith("vpc-cidr-assoc-")
1191 - vpc_info.vpcs[0].cidr_block_association_set[2].association_id.startswith("vpc-cidr-assoc-")
1192 - vpc_info.vpcs[0].cidr_block_association_set[0].cidr_block_state.state in ["associated", "associating"]
1193 - vpc_info.vpcs[0].cidr_block_association_set[1].cidr_block_state.state in ["associated", "associating"]
1194 - vpc_info.vpcs[0].cidr_block_association_set[2].cidr_block_state.state in ["associated", "associating"]
1195 - vpc_cidr in (vpc_info.vpcs[0].cidr_block_association_set | map(attribute="cidr_block") | list)
1196 - vpc_cidr_a in (vpc_info.vpcs[0].cidr_block_association_set | map(attribute="cidr_block") | list)
1197 - vpc_cidr_b in (vpc_info.vpcs[0].cidr_block_association_set | map(attribute="cidr_block") | list)
1198
1199 - name: Modify CIDR - no purge (no change)
1200 amazon.aws.ec2_vpc_net:
1201 state: present
1202 cidr_block:
1203 - "{{ vpc_cidr }}"
1204 - "{{ vpc_cidr_b }}"
1205 name: "{{ vpc_name }}"
1206 register: result
1207
1208 - name: Get VPC info
1209 amazon.aws.ec2_vpc_net_info:
1210 filters:
1211 tag:Name: "{{ vpc_name }}"
1212 register: vpc_info
1213
1214 - name: Assert the CIDRs didn't change
1215 ansible.builtin.assert:
1216 that:
1217 - result is successful
1218 - result is not changed
1219 - vpc_info.vpcs | length == 1
1220 - result.vpc.cidr_block == vpc_cidr
1221 - vpc_info.vpcs[0].cidr_block == vpc_cidr
1222 - result.vpc.cidr_block_association_set | length == 3
1223 - result.vpc.cidr_block_association_set[0].association_id.startswith("vpc-cidr-assoc-")
1224 - result.vpc.cidr_block_association_set[1].association_id.startswith("vpc-cidr-assoc-")
1225 - result.vpc.cidr_block_association_set[2].association_id.startswith("vpc-cidr-assoc-")
1226 - result.vpc.cidr_block_association_set[0].cidr_block_state.state in ["associated", "associating"]
1227 - result.vpc.cidr_block_association_set[1].cidr_block_state.state in ["associated", "associating"]
1228 - result.vpc.cidr_block_association_set[2].cidr_block_state.state in ["associated", "associating"]
1229 - vpc_cidr in (result.vpc.cidr_block_association_set | map(attribute="cidr_block") | list)
1230 - vpc_cidr_a in (result.vpc.cidr_block_association_set | map(attribute="cidr_block") | list)
1231 - vpc_cidr_b in (result.vpc.cidr_block_association_set | map(attribute="cidr_block") | list)
1232 - vpc_info.vpcs[0].cidr_block_association_set | length == 3
1233 - vpc_info.vpcs[0].cidr_block_association_set[0].association_id.startswith("vpc-cidr-assoc-")
1234 - vpc_info.vpcs[0].cidr_block_association_set[1].association_id.startswith("vpc-cidr-assoc-")
1235 - vpc_info.vpcs[0].cidr_block_association_set[2].association_id.startswith("vpc-cidr-assoc-")
1236 - vpc_info.vpcs[0].cidr_block_association_set[0].cidr_block_state.state in ["associated", "associating"]
1237 - vpc_info.vpcs[0].cidr_block_association_set[1].cidr_block_state.state in ["associated", "associating"]
1238 - vpc_info.vpcs[0].cidr_block_association_set[2].cidr_block_state.state in ["associated", "associating"]
1239 - vpc_cidr in (vpc_info.vpcs[0].cidr_block_association_set | map(attribute="cidr_block") | list)
1240 - vpc_cidr_a in (vpc_info.vpcs[0].cidr_block_association_set | map(attribute="cidr_block") | list)
1241 - vpc_cidr_b in (vpc_info.vpcs[0].cidr_block_association_set | map(attribute="cidr_block") | list)
1242
1243 - name: Modify CIDR - no purge (no change - list all - check mode)
1244 amazon.aws.ec2_vpc_net:
1245 state: present
1246 cidr_block:
1247 - "{{ vpc_cidr }}"
1248 - "{{ vpc_cidr_a }}"
1249 - "{{ vpc_cidr_b }}"
1250 name: "{{ vpc_name }}"
1251 register: result
1252
1253 - name: Get VPC info
1254 amazon.aws.ec2_vpc_net_info:
1255 filters:
1256 tag:Name: "{{ vpc_name }}"
1257 register: vpc_info
1258
1259 - name: Assert the CIDRs didn't change
1260 ansible.builtin.assert:
1261 that:
1262 - result is successful
1263 - result is not changed
1264 - vpc_info.vpcs | length == 1
1265 - result.vpc.cidr_block == vpc_cidr
1266 - vpc_info.vpcs[0].cidr_block == vpc_cidr
1267 - result.vpc.cidr_block_association_set | length == 3
1268 - result.vpc.cidr_block_association_set[0].association_id.startswith("vpc-cidr-assoc-")
1269 - result.vpc.cidr_block_association_set[1].association_id.startswith("vpc-cidr-assoc-")
1270 - result.vpc.cidr_block_association_set[2].association_id.startswith("vpc-cidr-assoc-")
1271 - result.vpc.cidr_block_association_set[0].cidr_block_state.state in ["associated", "associating"]
1272 - result.vpc.cidr_block_association_set[1].cidr_block_state.state in ["associated", "associating"]
1273 - result.vpc.cidr_block_association_set[2].cidr_block_state.state in ["associated", "associating"]
1274 - vpc_cidr in (result.vpc.cidr_block_association_set | map(attribute="cidr_block") | list)
1275 - vpc_cidr_a in (result.vpc.cidr_block_association_set | map(attribute="cidr_block") | list)
1276 - vpc_cidr_b in (result.vpc.cidr_block_association_set | map(attribute="cidr_block") | list)
1277 - vpc_info.vpcs[0].cidr_block_association_set | length == 3
1278 - vpc_info.vpcs[0].cidr_block_association_set[0].association_id.startswith("vpc-cidr-assoc-")
1279 - vpc_info.vpcs[0].cidr_block_association_set[1].association_id.startswith("vpc-cidr-assoc-")
1280 - vpc_info.vpcs[0].cidr_block_association_set[2].association_id.startswith("vpc-cidr-assoc-")
1281 - vpc_info.vpcs[0].cidr_block_association_set[0].cidr_block_state.state in ["associated", "associating"]
1282 - vpc_info.vpcs[0].cidr_block_association_set[1].cidr_block_state.state in ["associated", "associating"]
1283 - vpc_info.vpcs[0].cidr_block_association_set[2].cidr_block_state.state in ["associated", "associating"]
1284 - vpc_cidr in (vpc_info.vpcs[0].cidr_block_association_set | map(attribute="cidr_block") | list)
1285 - vpc_cidr_a in (vpc_info.vpcs[0].cidr_block_association_set | map(attribute="cidr_block") | list)
1286 - vpc_cidr_b in (vpc_info.vpcs[0].cidr_block_association_set | map(attribute="cidr_block") | list)
1287
1288 - name: Modify CIDR - no purge (no change - list all)
1289 amazon.aws.ec2_vpc_net:
1290 state: present
1291 cidr_block:
1292 - "{{ vpc_cidr }}"
1293 - "{{ vpc_cidr_a }}"
1294 - "{{ vpc_cidr_b }}"
1295 name: "{{ vpc_name }}"
1296 register: result
1297
1298 - name: Get VPC info
1299 amazon.aws.ec2_vpc_net_info:
1300 filters:
1301 tag:Name: "{{ vpc_name }}"
1302 register: vpc_info
1303
1304 - name: Assert the CIDRs didn't change
1305 ansible.builtin.assert:
1306 that:
1307 - result is successful
1308 - result is not changed
1309 - vpc_info.vpcs | length == 1
1310 - result.vpc.cidr_block == vpc_cidr
1311 - vpc_info.vpcs[0].cidr_block == vpc_cidr
1312 - result.vpc.cidr_block_association_set | length == 3
1313 - result.vpc.cidr_block_association_set[0].association_id.startswith("vpc-cidr-assoc-")
1314 - result.vpc.cidr_block_association_set[1].association_id.startswith("vpc-cidr-assoc-")
1315 - result.vpc.cidr_block_association_set[2].association_id.startswith("vpc-cidr-assoc-")
1316 - result.vpc.cidr_block_association_set[0].cidr_block_state.state in ["associated", "associating"]
1317 - result.vpc.cidr_block_association_set[1].cidr_block_state.state in ["associated", "associating"]
1318 - result.vpc.cidr_block_association_set[2].cidr_block_state.state in ["associated", "associating"]
1319 - vpc_cidr in (result.vpc.cidr_block_association_set | map(attribute="cidr_block") | list)
1320 - vpc_cidr_a in (result.vpc.cidr_block_association_set | map(attribute="cidr_block") | list)
1321 - vpc_cidr_b in (result.vpc.cidr_block_association_set | map(attribute="cidr_block") | list)
1322 - vpc_info.vpcs[0].cidr_block_association_set | length == 3
1323 - vpc_info.vpcs[0].cidr_block_association_set[0].association_id.startswith("vpc-cidr-assoc-")
1324 - vpc_info.vpcs[0].cidr_block_association_set[1].association_id.startswith("vpc-cidr-assoc-")
1325 - vpc_info.vpcs[0].cidr_block_association_set[2].association_id.startswith("vpc-cidr-assoc-")
1326 - vpc_info.vpcs[0].cidr_block_association_set[0].cidr_block_state.state in ["associated", "associating"]
1327 - vpc_info.vpcs[0].cidr_block_association_set[1].cidr_block_state.state in ["associated", "associating"]
1328 - vpc_info.vpcs[0].cidr_block_association_set[2].cidr_block_state.state in ["associated", "associating"]
1329 - vpc_cidr in (vpc_info.vpcs[0].cidr_block_association_set | map(attribute="cidr_block") | list)
1330 - vpc_cidr_a in (vpc_info.vpcs[0].cidr_block_association_set | map(attribute="cidr_block") | list)
1331 - vpc_cidr_b in (vpc_info.vpcs[0].cidr_block_association_set | map(attribute="cidr_block") | list)
1332
1333 - name: Modify CIDR - no purge (no change - different order - check mode)
1334 amazon.aws.ec2_vpc_net:
1335 state: present
1336 cidr_block:
1337 - "{{ vpc_cidr }}"
1338 - "{{ vpc_cidr_b }}"
1339 - "{{ vpc_cidr_a }}"
1340 name: "{{ vpc_name }}"
1341 register: result
1342
1343 - name: Get VPC info
1344 amazon.aws.ec2_vpc_net_info:
1345 filters:
1346 tag:Name: "{{ vpc_name }}"
1347 register: vpc_info
1348
1349 - name: Assert the CIDRs didn't change
1350 ansible.builtin.assert:
1351 that:
1352 - result is successful
1353 - result is not changed
1354 - vpc_info.vpcs | length == 1
1355 - result.vpc.cidr_block == vpc_cidr
1356 - vpc_info.vpcs[0].cidr_block == vpc_cidr
1357 - result.vpc.cidr_block_association_set | length == 3
1358 - result.vpc.cidr_block_association_set[0].association_id.startswith("vpc-cidr-assoc-")
1359 - result.vpc.cidr_block_association_set[1].association_id.startswith("vpc-cidr-assoc-")
1360 - result.vpc.cidr_block_association_set[2].association_id.startswith("vpc-cidr-assoc-")
1361 - result.vpc.cidr_block_association_set[0].cidr_block_state.state in ["associated", "associating"]
1362 - result.vpc.cidr_block_association_set[1].cidr_block_state.state in ["associated", "associating"]
1363 - result.vpc.cidr_block_association_set[2].cidr_block_state.state in ["associated", "associating"]
1364 - vpc_cidr in (result.vpc.cidr_block_association_set | map(attribute="cidr_block") | list)
1365 - vpc_cidr_a in (result.vpc.cidr_block_association_set | map(attribute="cidr_block") | list)
1366 - vpc_cidr_b in (result.vpc.cidr_block_association_set | map(attribute="cidr_block") | list)
1367 - vpc_info.vpcs[0].cidr_block_association_set | length == 3
1368 - vpc_info.vpcs[0].cidr_block_association_set[0].association_id.startswith("vpc-cidr-assoc-")
1369 - vpc_info.vpcs[0].cidr_block_association_set[1].association_id.startswith("vpc-cidr-assoc-")
1370 - vpc_info.vpcs[0].cidr_block_association_set[2].association_id.startswith("vpc-cidr-assoc-")
1371 - vpc_info.vpcs[0].cidr_block_association_set[0].cidr_block_state.state in ["associated", "associating"]
1372 - vpc_info.vpcs[0].cidr_block_association_set[1].cidr_block_state.state in ["associated", "associating"]
1373 - vpc_info.vpcs[0].cidr_block_association_set[2].cidr_block_state.state in ["associated", "associating"]
1374 - vpc_cidr in (vpc_info.vpcs[0].cidr_block_association_set | map(attribute="cidr_block") | list)
1375 - vpc_cidr_a in (vpc_info.vpcs[0].cidr_block_association_set | map(attribute="cidr_block") | list)
1376 - vpc_cidr_b in (vpc_info.vpcs[0].cidr_block_association_set | map(attribute="cidr_block") | list)
1377
1378 - name: Modify CIDR - no purge (no change - different order)
1379 amazon.aws.ec2_vpc_net:
1380 state: present
1381 cidr_block:
1382 - "{{ vpc_cidr }}"
1383 - "{{ vpc_cidr_b }}"
1384 - "{{ vpc_cidr_a }}"
1385 name: "{{ vpc_name }}"
1386 register: result
1387
1388 - name: Get VPC info
1389 amazon.aws.ec2_vpc_net_info:
1390 filters:
1391 tag:Name: "{{ vpc_name }}"
1392 register: vpc_info
1393
1394 - name: Assert the CIDRs didn't change
1395 ansible.builtin.assert:
1396 that:
1397 - result is successful
1398 - result is not changed
1399 - vpc_info.vpcs | length == 1
1400 - result.vpc.cidr_block == vpc_cidr
1401 - vpc_info.vpcs[0].cidr_block == vpc_cidr
1402 - result.vpc.cidr_block_association_set | length == 3
1403 - result.vpc.cidr_block_association_set[0].association_id.startswith("vpc-cidr-assoc-")
1404 - result.vpc.cidr_block_association_set[1].association_id.startswith("vpc-cidr-assoc-")
1405 - result.vpc.cidr_block_association_set[2].association_id.startswith("vpc-cidr-assoc-")
1406 - result.vpc.cidr_block_association_set[0].cidr_block_state.state in ["associated", "associating"]
1407 - result.vpc.cidr_block_association_set[1].cidr_block_state.state in ["associated", "associating"]
1408 - result.vpc.cidr_block_association_set[2].cidr_block_state.state in ["associated", "associating"]
1409 - vpc_cidr in (result.vpc.cidr_block_association_set | map(attribute="cidr_block") | list)
1410 - vpc_cidr_a in (result.vpc.cidr_block_association_set | map(attribute="cidr_block") | list)
1411 - vpc_cidr_b in (result.vpc.cidr_block_association_set | map(attribute="cidr_block") | list)
1412 - vpc_info.vpcs[0].cidr_block_association_set | length == 3
1413 - vpc_info.vpcs[0].cidr_block_association_set[0].association_id.startswith("vpc-cidr-assoc-")
1414 - vpc_info.vpcs[0].cidr_block_association_set[1].association_id.startswith("vpc-cidr-assoc-")
1415 - vpc_info.vpcs[0].cidr_block_association_set[2].association_id.startswith("vpc-cidr-assoc-")
1416 - vpc_info.vpcs[0].cidr_block_association_set[0].cidr_block_state.state in ["associated", "associating"]
1417 - vpc_info.vpcs[0].cidr_block_association_set[1].cidr_block_state.state in ["associated", "associating"]
1418 - vpc_info.vpcs[0].cidr_block_association_set[2].cidr_block_state.state in ["associated", "associating"]
1419 - vpc_cidr in (vpc_info.vpcs[0].cidr_block_association_set | map(attribute="cidr_block") | list)
1420 - vpc_cidr_a in (vpc_info.vpcs[0].cidr_block_association_set | map(attribute="cidr_block") | list)
1421 - vpc_cidr_b in (vpc_info.vpcs[0].cidr_block_association_set | map(attribute="cidr_block") | list)
1422
1423 - name: Modify CIDR - purge (check mode)
1424 amazon.aws.ec2_vpc_net:
1425 state: present
1426 cidr_block:
1427 - "{{ vpc_cidr }}"
1428 - "{{ vpc_cidr_b }}"
1429 name: "{{ vpc_name }}"
1430 purge_cidrs: true
1431 check_mode: true
1432 register: result
1433
1434 - name: Get VPC info
1435 amazon.aws.ec2_vpc_net_info:
1436 filters:
1437 tag:Name: "{{ vpc_name }}"
1438 register: vpc_info
1439
1440 - name: Check the CIDRs weren't changed
1441 ansible.builtin.assert:
1442 that:
1443 - result is successful
1444 - result is changed
1445 - vpc_info.vpcs | length == 1
1446 - vpc_info.vpcs[0].cidr_block == vpc_cidr
1447 - vpc_info.vpcs[0].cidr_block_association_set | length == 3
1448 - vpc_info.vpcs[0].cidr_block_association_set[0].association_id.startswith("vpc-cidr-assoc-")
1449 - vpc_info.vpcs[0].cidr_block_association_set[1].association_id.startswith("vpc-cidr-assoc-")
1450 - vpc_info.vpcs[0].cidr_block_association_set[2].association_id.startswith("vpc-cidr-assoc-")
1451 - vpc_info.vpcs[0].cidr_block_association_set[0].cidr_block_state.state in ["associated", "associating"]
1452 - vpc_info.vpcs[0].cidr_block_association_set[1].cidr_block_state.state in ["associated", "associating"]
1453 - vpc_info.vpcs[0].cidr_block_association_set[2].cidr_block_state.state in ["associated", "associating"]
1454 - vpc_cidr in (vpc_info.vpcs[0].cidr_block_association_set | map(attribute="cidr_block") | list)
1455 - vpc_cidr_a in (vpc_info.vpcs[0].cidr_block_association_set | map(attribute="cidr_block") | list)
1456 - vpc_cidr_b in (vpc_info.vpcs[0].cidr_block_association_set | map(attribute="cidr_block") | list)
1457
1458 - name: Modify CIDR - purge
1459 amazon.aws.ec2_vpc_net:
1460 state: present
1461 cidr_block:
1462 - "{{ vpc_cidr }}"
1463 - "{{ vpc_cidr_b }}"
1464 name: "{{ vpc_name }}"
1465 purge_cidrs: true
1466 register: result
1467
1468 - name: Get VPC info
1469 amazon.aws.ec2_vpc_net_info:
1470 filters:
1471 tag:Name: "{{ vpc_name }}"
1472 register: vpc_info
1473
1474 - name: Assert the CIDRs changed
1475 ansible.builtin.assert:
1476 that:
1477 - result is successful
1478 - result is changed
1479 - result.vpc.id == vpc_1
1480 - vpc_info.vpcs | length == 1
1481 - result.vpc.cidr_block == vpc_cidr
1482 - vpc_info.vpcs[0].cidr_block == vpc_cidr
1483 - result.vpc.cidr_block_association_set | selectattr('cidr_block_state.state', 'equalto', 'associated') | map(attribute='cidr_block') | list | length ==
1484 2
1485 - vpc_cidr in (result.vpc.cidr_block_association_set | selectattr('cidr_block_state.state', 'equalto', 'associated') | map(attribute='cidr_block') | list)
1486 - vpc_cidr_a not in (result.vpc.cidr_block_association_set | selectattr('cidr_block_state.state', 'equalto', 'associated') | map(attribute='cidr_block'))
1487 - vpc_cidr_b in (result.vpc.cidr_block_association_set | selectattr('cidr_block_state.state', 'equalto', 'associated') | map(attribute='cidr_block'))
1488 - vpc_info.vpcs[0].cidr_block_association_set | selectattr('cidr_block_state.state', 'equalto', 'associated') | map(attribute='cidr_block') | list | length
1489 == 2
1490 - vpc_cidr in (vpc_info.vpcs[0].cidr_block_association_set | selectattr('cidr_block_state.state', 'equalto', 'associated') | map(attribute='cidr_block')
1491 | list)
1492 - vpc_cidr_a not in (vpc_info.vpcs[0].cidr_block_association_set | selectattr('cidr_block_state.state', 'equalto', 'associated') | map(attribute='cidr_block')
1493 | list)
1494 - vpc_cidr_b in (vpc_info.vpcs[0].cidr_block_association_set | selectattr('cidr_block_state.state', 'equalto', 'associated') | map(attribute='cidr_block')
1495 | list)
1496
1497 - name: Modify CIDR - purge (no change)
1498 amazon.aws.ec2_vpc_net:
1499 state: present
1500 cidr_block:
1501 - "{{ vpc_cidr }}"
1502 - "{{ vpc_cidr_b }}"
1503 name: "{{ vpc_name }}"
1504 purge_cidrs: true
1505 register: result
1506
1507 - name: Get VPC info
1508 amazon.aws.ec2_vpc_net_info:
1509 filters:
1510 tag:Name: "{{ vpc_name }}"
1511 register: vpc_info
1512
1513 - name: Assert the CIDRs didn't change
1514 ansible.builtin.assert:
1515 that:
1516 - result is successful
1517 - result is not changed
1518 - result.vpc.id == vpc_1
1519 - vpc_info.vpcs | length == 1
1520 - result.vpc.cidr_block == vpc_cidr
1521 - vpc_info.vpcs[0].cidr_block == vpc_cidr
1522 - result.vpc.cidr_block_association_set | selectattr('cidr_block_state.state', 'equalto', 'associated') | map(attribute='cidr_block') | list | length ==
1523 2
1524 - vpc_cidr in (result.vpc.cidr_block_association_set | selectattr('cidr_block_state.state', 'equalto', 'associated') | map(attribute='cidr_block') | list)
1525 - vpc_cidr_a not in (result.vpc.cidr_block_association_set | selectattr('cidr_block_state.state', 'equalto', 'associated') | map(attribute='cidr_block')
1526 | list)
1527 - vpc_cidr_b in (result.vpc.cidr_block_association_set | selectattr('cidr_block_state.state', 'equalto', 'associated') | map(attribute='cidr_block') | list)
1528 - vpc_info.vpcs[0].cidr_block_association_set | selectattr('cidr_block_state.state', 'equalto', 'associated') | map(attribute='cidr_block') | list | length
1529 == 2
1530 - vpc_cidr in (vpc_info.vpcs[0].cidr_block_association_set | selectattr('cidr_block_state.state', 'equalto', 'associated') | map(attribute='cidr_block')
1531 | list)
1532 - vpc_cidr_a not in (vpc_info.vpcs[0].cidr_block_association_set | selectattr('cidr_block_state.state', 'equalto', 'associated') | map(attribute='cidr_block')
1533 | list)
1534 - vpc_cidr_b in (vpc_info.vpcs[0].cidr_block_association_set | selectattr('cidr_block_state.state', 'equalto', 'associated') | map(attribute='cidr_block')
1535 | list)
1536
1537 # ============================================================
1538
1539 - name: Remove IPv6 CIDR association from VPC in check mode
1540 amazon.aws.ec2_vpc_net:
1541 state: present
1542 cidr_block: "{{ vpc_cidr }}"
1543 name: "{{ vpc_name }}"
1544 ipv6_cidr: false
1545 check_mode: true
1546 register: result
1547 - name: Assert configuration would change
1548 ansible.builtin.assert:
1549 that:
1550 - result is successful
1551 - result is changed
1552
1553 - name: Set IPv6 CIDR association to VPC, no change expected
1554 # I.e. assert the previous ec2_vpc_net task in check_mode did not
1555 # mistakenly modify the VPC configuration.
1556 amazon.aws.ec2_vpc_net:
1557 state: present
1558 cidr_block: "{{ vpc_cidr }}"
1559 name: "{{ vpc_name }}"
1560 ipv6_cidr: true
1561 register: result
1562 - name: Assert configuration did not change
1563 ansible.builtin.assert:
1564 that:
1565 - result is successful
1566 - result is not changed
1567
1568 - name: Remove IPv6 CIDR association from VPC
1569 amazon.aws.ec2_vpc_net:
1570 state: present
1571 cidr_block: "{{ vpc_cidr }}"
1572 name: "{{ vpc_name }}"
1573 ipv6_cidr: false
1574 register: result
1575 - name: Assert IPv6 CIDR association removed from VPC
1576 ansible.builtin.assert:
1577 that:
1578 - result is successful
1579 - result is changed
1580 - result.vpc.ipv6_cidr_block_association_set | length == 1
1581 - result.vpc.ipv6_cidr_block_association_set[0].association_id.startswith("vpc-cidr-assoc-")
1582 - result.vpc.ipv6_cidr_block_association_set[0].ipv6_cidr_block is defined and result.vpc.ipv6_cidr_block_association_set[0].ipv6_cidr_block is ansible.utils.ipv6
1583 - result.vpc.ipv6_cidr_block_association_set[0].ipv6_cidr_block_state.state in ["disassociated"]
1584
1585 - name: Retry to remove IPv6 CIDR association from VPC
1586 amazon.aws.ec2_vpc_net:
1587 state: present
1588 cidr_block: "{{ vpc_cidr }}"
1589 name: "{{ vpc_name }}"
1590 ipv6_cidr: false
1591 register: result
1592
1593 - name: Assert the task passes and there is no change
1594 ansible.builtin.assert:
1595 that:
1596 - result is successful
1597 - result is not changed
1598
1599 - name: Add IPv6 CIDR association to VPC again
1600 amazon.aws.ec2_vpc_net:
1601 state: present
1602 cidr_block: "{{ vpc_cidr }}"
1603 name: "{{ vpc_name }}"
1604 ipv6_cidr: true
1605 register: result
1606 - name: Assert configuration change
1607 ansible.builtin.assert:
1608 that:
1609 - result is successful
1610 - result is changed
1611 # Because the IPv6 CIDR was associated, then disassociated, then reassociated,
1612 # now there should be one disassociated block and one associated block.
1613 - result.vpc.ipv6_cidr_block_association_set | length == 2
1614 - result.vpc.ipv6_cidr_block_association_set[0].association_id.startswith("vpc-cidr-assoc-")
1615 - result.vpc.ipv6_cidr_block_association_set[0].ipv6_cidr_block is defined and result.vpc.ipv6_cidr_block_association_set[0].ipv6_cidr_block is ansible.utils.ipv6
1616 - result.vpc.ipv6_cidr_block_association_set[0].ipv6_cidr_block_state.state in ["disassociated", "disassociating"]
1617 - result.vpc.ipv6_cidr_block_association_set[1].association_id.startswith("vpc-cidr-assoc-")
1618 - result.vpc.ipv6_cidr_block_association_set[1].ipv6_cidr_block is defined and result.vpc.ipv6_cidr_block_association_set[1].ipv6_cidr_block is ansible.utils.ipv6
1619 - result.vpc.ipv6_cidr_block_association_set[1].ipv6_cidr_block_state.state in ["associated", "associating"]
1620
1621 # ============================================================
1622
1623 - name: Test check mode to delete a VPC
1624 amazon.aws.ec2_vpc_net:
1625 cidr_block: "{{ vpc_cidr }}"
1626 name: "{{ vpc_name }}"
1627 state: absent
1628 check_mode: true
1629 register: result
1630
1631 - name: Assert that a change would have been made
1632 ansible.builtin.assert:
1633 that:
1634 - result is changed
1635
1636 # ============================================================
1637
1638 always:
1639 - name: Describe VPCs before deleting them (for debugging)
1640 amazon.aws.ec2_vpc_net_info:
1641 ignore_errors: true
1642
1643 - name: Replace the DHCP options set so the new one can be deleted
1644 amazon.aws.ec2_vpc_net:
1645 cidr_block: "{{ vpc_cidr }}"
1646 name: "{{ vpc_name }}"
1647 state: present
1648 multi_ok: false
1649 dhcp_opts_id: "{{ default_dhcp_options_id }}"
1650 ignore_errors: true
1651
1652 - name: Remove the DHCP option set
1653 amazon.aws.ec2_vpc_dhcp_option:
1654 dhcp_options_id: "{{ new_dhcp.dhcp_options_id }}"
1655 state: absent
1656 ignore_errors: true
1657
1658 - name: Remove the VPC
1659 amazon.aws.ec2_vpc_net:
1660 cidr_block: "{{ vpc_cidr }}"
1661 name: "{{ vpc_name }}"
1662 state: absent
1663 ignore_errors: true