-
Notifications
You must be signed in to change notification settings - Fork 342
/
main.yml
684 lines (603 loc) · 24.4 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
---
- module_defaults:
group/aws:
access_key: "{{ aws_access_key }}"
secret_key: "{{ aws_secret_key }}"
session_token: "{{ security_token | default(omit) }}"
region: "{{ aws_region }}"
block:
# ============================================================
- name: create a VPC
amazon.aws.ec2_vpc_net:
name: "{{ resource_prefix }}-vpc"
state: present
cidr_block: "{{ vpc_cidr }}"
ipv6_cidr: true
tags:
Name: "{{ resource_prefix }}-vpc"
Description: Created by ansible-test
register: vpc_result
- ansible.builtin.set_fact:
vpc_ipv6_cidr: "{{ vpc_result.vpc.ipv6_cidr_block_association_set[0].ipv6_cidr_block }}"
- ansible.builtin.set_fact:
subnet_ipv6_cidr: "{{ vpc_ipv6_cidr | regex_replace('::/.*', '::/64') }}"
# ============================================================
- name: check subnet does not exist
amazon.aws.ec2_vpc_subnet_info:
filters:
tag:Name: "{{ec2_vpc_subnet_name}}"
register: vpc_subnet_info
- name: Assert info result is zero
ansible.builtin.assert:
that:
- (vpc_subnet_info.subnets|length) == 0
- name: create subnet (expected changed=true) (CHECK MODE)
amazon.aws.ec2_vpc_subnet:
cidr: "{{ subnet_cidr }}"
az: "{{ availability_zone }}"
vpc_id: "{{ vpc_result.vpc.id }}"
tags:
Name: "{{ec2_vpc_subnet_name}}"
Description: "{{ec2_vpc_subnet_description}}"
state: present
check_mode: true
register: vpc_subnet_create
- name: assert creation would happen
ansible.builtin.assert:
that:
- vpc_subnet_create is changed
- name: create subnet (expected changed=true)
amazon.aws.ec2_vpc_subnet:
cidr: "{{ subnet_cidr }}"
az: "{{ availability_zone }}"
vpc_id: "{{ vpc_result.vpc.id }}"
tags:
Name: "{{ec2_vpc_subnet_name}}"
Description: "{{ec2_vpc_subnet_description}}"
state: present
register: vpc_subnet_create
- name: assert creation happened (expected changed=true)
ansible.builtin.assert:
that:
- vpc_subnet_create
- "'ec2:CreateTags' not in vpc_subnet_create.resource_actions"
- "'ec2:DeleteTags' not in vpc_subnet_create.resource_actions"
- vpc_subnet_create.subnet.id.startswith("subnet-")
- '"Name" in vpc_subnet_create.subnet.tags and vpc_subnet_create.subnet.tags["Name"] == ec2_vpc_subnet_name'
- '"Description" in vpc_subnet_create.subnet.tags and vpc_subnet_create.subnet.tags["Description"] == ec2_vpc_subnet_description'
- name: get info about the subnet
amazon.aws.ec2_vpc_subnet_info:
subnet_ids: "{{ vpc_subnet_create.subnet.id }}"
register: vpc_subnet_info
- name: Assert info result matches create result
ansible.builtin.assert:
that:
- vpc_subnet_info.subnets | length == 1
- '"assign_ipv6_address_on_creation" in subnet_info'
- subnet_info.assign_ipv6_address_on_creation == False
- '"availability_zone" in subnet_info'
- subnet_info.availability_zone == availability_zone
- '"available_ip_address_count" in subnet_info'
- '"cidr_block" in subnet_info'
- subnet_info.cidr_block == subnet_cidr
- '"default_for_az" in subnet_info'
- '"id" in subnet_info'
- subnet_info.id == vpc_subnet_create.subnet.id
- '"map_public_ip_on_launch" in subnet_info'
- subnet_info.map_public_ip_on_launch == False
- '"state" in subnet_info'
- '"subnet_id" in subnet_info'
- subnet_info.subnet_id == vpc_subnet_create.subnet.id
- '"tags" in subnet_info'
- subnet_info.tags["Description"] == ec2_vpc_subnet_description
- subnet_info.tags["Name"] == vpc_subnet_create.subnet.tags["Name"]
- '"vpc_id" in subnet_info'
- subnet_info.vpc_id == vpc_result.vpc.id
vars:
subnet_info: "{{ vpc_subnet_info.subnets[0] }}"
# ============================================================
- name: recreate subnet (expected changed=false) (CHECK MODE)
amazon.aws.ec2_vpc_subnet:
cidr: "{{ subnet_cidr }}"
az: "{{ availability_zone }}"
vpc_id: "{{ vpc_result.vpc.id }}"
tags:
Name: "{{ec2_vpc_subnet_name}}"
Description: "{{ec2_vpc_subnet_description}}"
state: present
check_mode: true
register: vpc_subnet_recreate
- name: assert recreation changed nothing (expected changed=false)
ansible.builtin.assert:
that:
- vpc_subnet_recreate is not changed
- name: recreate subnet (expected changed=false)
amazon.aws.ec2_vpc_subnet:
cidr: "{{ subnet_cidr }}"
az: "{{ availability_zone }}"
vpc_id: "{{ vpc_result.vpc.id }}"
tags:
Name: "{{ec2_vpc_subnet_name}}"
Description: "{{ec2_vpc_subnet_description}}"
state: present
register: vpc_subnet_recreate
- name: assert recreation changed nothing (expected changed=false)
ansible.builtin.assert:
that:
- vpc_subnet_recreate is not changed
- vpc_subnet_recreate.subnet == vpc_subnet_create.subnet
# ============================================================
- name: update subnet so instances launched in it are assigned an IP (CHECK MODE)
amazon.aws.ec2_vpc_subnet:
cidr: "{{ subnet_cidr }}"
az: "{{ availability_zone }}"
vpc_id: "{{ vpc_result.vpc.id }}"
tags:
Name: "{{ec2_vpc_subnet_name}}"
Description: "{{ec2_vpc_subnet_description}}"
state: present
map_public: true
check_mode: true
register: vpc_subnet_modify
- name: assert subnet changed
ansible.builtin.assert:
that:
- vpc_subnet_modify is changed
- name: update subnet so instances launched in it are assigned an IP
amazon.aws.ec2_vpc_subnet:
cidr: "{{ subnet_cidr }}"
az: "{{ availability_zone }}"
vpc_id: "{{ vpc_result.vpc.id }}"
tags:
Name: "{{ec2_vpc_subnet_name}}"
Description: "{{ec2_vpc_subnet_description}}"
state: present
map_public: true
register: vpc_subnet_modify
- name: assert subnet changed
ansible.builtin.assert:
that:
- vpc_subnet_modify is changed
- vpc_subnet_modify.subnet.map_public_ip_on_launch
# ============================================================
- name: add invalid ipv6 block to subnet (expected failed)
amazon.aws.ec2_vpc_subnet:
cidr: "{{ subnet_cidr }}"
az: "{{ availability_zone }}"
vpc_id: "{{ vpc_result.vpc.id }}"
ipv6_cidr: 2001:db8::/64
tags:
Name: "{{ec2_vpc_subnet_name}}"
Description: "{{ec2_vpc_subnet_description}}"
state: present
register: vpc_subnet_ipv6_failed
ignore_errors: true
- name: assert failure happened (expected failed)
ansible.builtin.assert:
that:
- vpc_subnet_ipv6_failed is failed
- "'Couldn\\'t associate ipv6 cidr' in vpc_subnet_ipv6_failed.msg"
# ============================================================
- name: add a tag (expected changed=true) (CHECK MODE)
amazon.aws.ec2_vpc_subnet:
cidr: "{{ subnet_cidr }}"
az: "{{ availability_zone }}"
vpc_id: "{{ vpc_result.vpc.id }}"
tags:
Name: "{{ec2_vpc_subnet_name}}"
Description: "{{ec2_vpc_subnet_description}}"
AnotherTag: SomeValue
state: present
check_mode: true
register: vpc_subnet_add_a_tag
- name: assert tag addition happened (expected changed=true)
ansible.builtin.assert:
that:
- vpc_subnet_add_a_tag is changed
- name: add a tag (expected changed=true)
amazon.aws.ec2_vpc_subnet:
cidr: "{{ subnet_cidr }}"
az: "{{ availability_zone }}"
vpc_id: "{{ vpc_result.vpc.id }}"
tags:
Name: "{{ec2_vpc_subnet_name}}"
Description: "{{ec2_vpc_subnet_description}}"
AnotherTag: SomeValue
state: present
register: vpc_subnet_add_a_tag
- name: assert tag addition happened (expected changed=true)
ansible.builtin.assert:
that:
- vpc_subnet_add_a_tag is changed
- '"Name" in vpc_subnet_add_a_tag.subnet.tags and vpc_subnet_add_a_tag.subnet.tags["Name"] == ec2_vpc_subnet_name'
- '"Description" in vpc_subnet_add_a_tag.subnet.tags and vpc_subnet_add_a_tag.subnet.tags["Description"] == ec2_vpc_subnet_description'
- '"AnotherTag" in vpc_subnet_add_a_tag.subnet.tags and vpc_subnet_add_a_tag.subnet.tags["AnotherTag"] == "SomeValue"'
- name: Get info by tag
amazon.aws.ec2_vpc_subnet_info:
filters:
tag:Name: "{{ec2_vpc_subnet_name}}"
register: vpc_subnet_info_by_tag
- name: assert info matches expected output
ansible.builtin.assert:
that:
- vpc_subnet_info_by_tag.subnets[0].id == vpc_subnet_add_a_tag.subnet.id
- (vpc_subnet_info_by_tag.subnets[0].tags|length) == 3
- '"Description" in vpc_subnet_info_by_tag.subnets[0].tags and vpc_subnet_info_by_tag.subnets[0].tags["Description"] == ec2_vpc_subnet_description'
- '"AnotherTag" in vpc_subnet_info_by_tag.subnets[0].tags and vpc_subnet_info_by_tag.subnets[0].tags["AnotherTag"] == "SomeValue"'
# ============================================================
- name: remove tags with default purge_tags=true (expected changed=true) (CHECK MODE)
amazon.aws.ec2_vpc_subnet:
cidr: "{{ subnet_cidr }}"
az: "{{ availability_zone }}"
vpc_id: "{{ vpc_result.vpc.id }}"
tags:
AnotherTag: SomeValue
state: present
check_mode: true
register: vpc_subnet_remove_tags
- name: assert tag removal happened (expected changed=true)
ansible.builtin.assert:
that:
- vpc_subnet_remove_tags is changed
- name: remove tags with default purge_tags=true (expected changed=true)
amazon.aws.ec2_vpc_subnet:
cidr: "{{ subnet_cidr }}"
az: "{{ availability_zone }}"
vpc_id: "{{ vpc_result.vpc.id }}"
tags:
AnotherTag: SomeValue
state: present
register: vpc_subnet_remove_tags
- name: assert tag removal happened (expected changed=true)
ansible.builtin.assert:
that:
- vpc_subnet_remove_tags is changed
- '"Name" not in vpc_subnet_remove_tags.subnet.tags'
- '"Description" not in vpc_subnet_remove_tags.subnet.tags'
- '"AnotherTag" in vpc_subnet_remove_tags.subnet.tags and vpc_subnet_remove_tags.subnet.tags["AnotherTag"] == "SomeValue"'
- name: Check tags by info
amazon.aws.ec2_vpc_subnet_info:
subnet_id: "{{ vpc_subnet_remove_tags.subnet.id }}"
register: vpc_subnet_info_removed_tags
- name: assert info matches expected output
ansible.builtin.assert:
that:
- '"Name" not in vpc_subnet_info_removed_tags.subnets[0].tags'
- '"Description" not in vpc_subnet_info_removed_tags.subnets[0].tags'
- '"AnotherTag" in vpc_subnet_info_removed_tags.subnets[0].tags and vpc_subnet_info_removed_tags.subnets[0].tags["AnotherTag"] == "SomeValue"'
# ============================================================
- name: change tags with purge_tags=false (expected changed=true) (CHECK MODE)
amazon.aws.ec2_vpc_subnet:
cidr: "{{ subnet_cidr }}"
az: "{{ availability_zone }}"
vpc_id: "{{ vpc_result.vpc.id }}"
tags:
Name: "{{ec2_vpc_subnet_name}}"
Description: "{{ec2_vpc_subnet_description}}"
state: present
purge_tags: false
check_mode: true
register: vpc_subnet_change_tags
- name: assert tag addition happened (expected changed=true)
ansible.builtin.assert:
that:
- vpc_subnet_change_tags is changed
- name: change tags with purge_tags=false (expected changed=true)
amazon.aws.ec2_vpc_subnet:
cidr: "{{ subnet_cidr }}"
az: "{{ availability_zone }}"
vpc_id: "{{ vpc_result.vpc.id }}"
tags:
Name: "{{ec2_vpc_subnet_name}}"
Description: "{{ec2_vpc_subnet_description}}"
state: present
purge_tags: false
register: vpc_subnet_change_tags
- name: assert tag addition happened (expected changed=true)
ansible.builtin.assert:
that:
- vpc_subnet_change_tags is changed
- '"Name" in vpc_subnet_change_tags.subnet.tags and vpc_subnet_change_tags.subnet.tags["Name"] == ec2_vpc_subnet_name'
- '"Description" in vpc_subnet_change_tags.subnet.tags and vpc_subnet_change_tags.subnet.tags["Description"] == ec2_vpc_subnet_description'
- '"AnotherTag" in vpc_subnet_change_tags.subnet.tags and vpc_subnet_change_tags.subnet.tags["AnotherTag"] == "SomeValue"'
# ============================================================
- name: test state=absent (expected changed=true) (CHECK MODE)
amazon.aws.ec2_vpc_subnet:
cidr: "{{ subnet_cidr }}"
vpc_id: "{{ vpc_result.vpc.id }}"
state: absent
check_mode: true
register: result
- name: assert state=absent (expected changed=true)
ansible.builtin.assert:
that:
- result is changed
- name: test state=absent (expected changed=true)
amazon.aws.ec2_vpc_subnet:
cidr: "{{ subnet_cidr }}"
vpc_id: "{{ vpc_result.vpc.id }}"
state: absent
register: result
- name: assert state=absent (expected changed=true)
ansible.builtin.assert:
that:
- result is changed
# ============================================================
- name: test state=absent (expected changed=false) (CHECK MODE)
amazon.aws.ec2_vpc_subnet:
cidr: "{{ subnet_cidr }}"
vpc_id: "{{ vpc_result.vpc.id }}"
state: absent
check_mode: true
register: result
- name: assert state=absent (expected changed=false)
ansible.builtin.assert:
that:
- result is not changed
- name: test state=absent (expected changed=false)
amazon.aws.ec2_vpc_subnet:
cidr: "{{ subnet_cidr }}"
vpc_id: "{{ vpc_result.vpc.id }}"
state: absent
register: result
- name: assert state=absent (expected changed=false)
ansible.builtin.assert:
that:
- result is not changed
# ============================================================
- name: create subnet without AZ (CHECK MODE)
amazon.aws.ec2_vpc_subnet:
cidr: "{{ subnet_cidr }}"
vpc_id: "{{ vpc_result.vpc.id }}"
state: present
check_mode: true
register: subnet_without_az
- name: check that subnet without AZ works fine
ansible.builtin.assert:
that:
- subnet_without_az is changed
- name: create subnet without AZ
amazon.aws.ec2_vpc_subnet:
cidr: "{{ subnet_cidr }}"
vpc_id: "{{ vpc_result.vpc.id }}"
state: present
register: subnet_without_az
- name: check that subnet without AZ works fine
ansible.builtin.assert:
that:
- subnet_without_az is changed
# ============================================================
- name: remove subnet without AZ (CHECK MODE)
amazon.aws.ec2_vpc_subnet:
cidr: "{{ subnet_cidr }}"
vpc_id: "{{ vpc_result.vpc.id }}"
state: absent
check_mode: true
register: result
- name: assert state=absent (expected changed=true)
ansible.builtin.assert:
that:
- result is changed
- name: remove subnet without AZ
amazon.aws.ec2_vpc_subnet:
cidr: "{{ subnet_cidr }}"
vpc_id: "{{ vpc_result.vpc.id }}"
state: absent
register: result
- name: assert state=absent (expected changed=true)
ansible.builtin.assert:
that:
- result is changed
# ============================================================
- name: create subnet with IPv6 (expected changed=true) (CHECK MODE)
amazon.aws.ec2_vpc_subnet:
cidr: "{{ subnet_cidr }}"
vpc_id: "{{ vpc_result.vpc.id }}"
ipv6_cidr: "{{ subnet_ipv6_cidr }}"
assign_instances_ipv6: true
state: present
tags:
Name: "{{ec2_vpc_subnet_name}}"
Description: "{{ec2_vpc_subnet_description}}"
check_mode: true
register: vpc_subnet_ipv6_create
- name: assert creation with IPv6 happened (expected changed=true)
ansible.builtin.assert:
that:
- vpc_subnet_ipv6_create is changed
- name: create subnet with IPv6 (expected changed=true)
amazon.aws.ec2_vpc_subnet:
cidr: "{{ subnet_cidr }}"
vpc_id: "{{ vpc_result.vpc.id }}"
ipv6_cidr: "{{ subnet_ipv6_cidr }}"
assign_instances_ipv6: true
state: present
tags:
Name: "{{ec2_vpc_subnet_name}}"
Description: "{{ec2_vpc_subnet_description}}"
register: vpc_subnet_ipv6_create
- name: assert creation with IPv6 happened (expected changed=true)
ansible.builtin.assert:
that:
- vpc_subnet_ipv6_create is changed
- vpc_subnet_ipv6_create.subnet.id.startswith("subnet-")
- vpc_subnet_ipv6_create.subnet.ipv6_cidr_block == subnet_ipv6_cidr
- '"Name" in vpc_subnet_ipv6_create.subnet.tags and vpc_subnet_ipv6_create.subnet.tags["Name"] == ec2_vpc_subnet_name'
- '"Description" in vpc_subnet_ipv6_create.subnet.tags and vpc_subnet_ipv6_create.subnet.tags["Description"] == ec2_vpc_subnet_description'
- vpc_subnet_ipv6_create.subnet.assign_ipv6_address_on_creation
# ============================================================
- name: recreate subnet (expected changed=false) (CHECK MODE)
amazon.aws.ec2_vpc_subnet:
cidr: "{{ subnet_cidr }}"
vpc_id: "{{ vpc_result.vpc.id }}"
ipv6_cidr: "{{ subnet_ipv6_cidr }}"
assign_instances_ipv6: true
state: present
tags:
Name: "{{ec2_vpc_subnet_name}}"
Description: "{{ec2_vpc_subnet_description}}"
check_mode: true
register: vpc_subnet_ipv6_recreate
- name: assert recreation changed nothing (expected changed=false)
ansible.builtin.assert:
that:
- vpc_subnet_ipv6_recreate is not changed
- name: recreate subnet (expected changed=false)
amazon.aws.ec2_vpc_subnet:
cidr: "{{ subnet_cidr }}"
vpc_id: "{{ vpc_result.vpc.id }}"
ipv6_cidr: "{{ subnet_ipv6_cidr }}"
assign_instances_ipv6: true
state: present
tags:
Name: "{{ec2_vpc_subnet_name}}"
Description: "{{ec2_vpc_subnet_description}}"
register: vpc_subnet_ipv6_recreate
- name: assert recreation changed nothing (expected changed=false)
ansible.builtin.assert:
that:
- vpc_subnet_ipv6_recreate is not changed
- vpc_subnet_ipv6_recreate.subnet == vpc_subnet_ipv6_create.subnet
# ============================================================
- name: change subnet assign_instances_ipv6 attribute (expected changed=true) (CHECK MODE)
amazon.aws.ec2_vpc_subnet:
cidr: "{{ subnet_cidr }}"
vpc_id: "{{ vpc_result.vpc.id }}"
ipv6_cidr: "{{ subnet_ipv6_cidr }}"
assign_instances_ipv6: false
state: present
purge_tags: false
check_mode: true
register: vpc_change_attribute
- name: assert assign_instances_ipv6 attribute changed (expected changed=true)
ansible.builtin.assert:
that:
- vpc_change_attribute is changed
- name: change subnet assign_instances_ipv6 attribute (expected changed=true)
amazon.aws.ec2_vpc_subnet:
cidr: "{{ subnet_cidr }}"
vpc_id: "{{ vpc_result.vpc.id }}"
ipv6_cidr: "{{ subnet_ipv6_cidr }}"
assign_instances_ipv6: false
state: present
purge_tags: false
register: vpc_change_attribute
- name: assert assign_instances_ipv6 attribute changed (expected changed=true)
ansible.builtin.assert:
that:
- vpc_change_attribute is changed
- not vpc_change_attribute.subnet.assign_ipv6_address_on_creation
# ============================================================
- name: add second subnet with duplicate ipv6 cidr (expected failure)
amazon.aws.ec2_vpc_subnet:
cidr: "{{ subnet_cidr_b }}"
vpc_id: "{{ vpc_result.vpc.id }}"
ipv6_cidr: "{{ subnet_ipv6_cidr }}"
state: present
purge_tags: false
register: vpc_add_duplicate_ipv6
ignore_errors: true
- name: assert graceful failure (expected failed)
ansible.builtin.assert:
that:
- vpc_add_duplicate_ipv6 is failed
- '"The IPv6 CIDR "+testChar+subnet_ipv6_cidr+testChar+" conflicts with another subnet" in vpc_add_duplicate_ipv6.msg'
vars:
testChar: "'"
# ============================================================
- name: remove subnet ipv6 cidr (expected changed=true) (CHECK MODE)
amazon.aws.ec2_vpc_subnet:
cidr: "{{ subnet_cidr }}"
vpc_id: "{{ vpc_result.vpc.id }}"
state: present
purge_tags: false
check_mode: true
register: vpc_remove_ipv6_cidr
- name: assert subnet ipv6 cidr removed (expected changed=true)
ansible.builtin.assert:
that:
- vpc_remove_ipv6_cidr is changed
- name: remove subnet ipv6 cidr (expected changed=true)
amazon.aws.ec2_vpc_subnet:
cidr: "{{ subnet_cidr }}"
vpc_id: "{{ vpc_result.vpc.id }}"
state: present
purge_tags: false
register: vpc_remove_ipv6_cidr
- name: assert subnet ipv6 cidr removed (expected changed=true)
ansible.builtin.assert:
that:
- vpc_remove_ipv6_cidr is changed
- vpc_remove_ipv6_cidr.subnet.ipv6_cidr_block == ''
- not vpc_remove_ipv6_cidr.subnet.assign_ipv6_address_on_creation
# ============================================================
- name: test adding a tag that looks like a boolean to the subnet (CHECK MODE)
amazon.aws.ec2_vpc_subnet:
cidr: "{{ subnet_cidr }}"
vpc_id: "{{ vpc_result.vpc.id }}"
state: present
purge_tags: false
tags:
looks_like_boolean: true
check_mode: true
register: vpc_subnet_info
- name: assert a tag was added
ansible.builtin.assert:
that:
- vpc_subnet_info is changed
- name: test adding a tag that looks like a boolean to the subnet
amazon.aws.ec2_vpc_subnet:
cidr: "{{ subnet_cidr }}"
vpc_id: "{{ vpc_result.vpc.id }}"
state: present
purge_tags: false
tags:
looks_like_boolean: true
register: vpc_subnet_info
- name: assert a tag was added
ansible.builtin.assert:
that:
- vpc_subnet_info is changed
- vpc_subnet_info.subnet.tags.looks_like_boolean == "True"
# ============================================================
- name: test idempotence adding a tag that looks like a boolean (CHECK MODE)
amazon.aws.ec2_vpc_subnet:
cidr: "{{ subnet_cidr }}"
vpc_id: "{{ vpc_result.vpc.id }}"
state: present
purge_tags: false
tags:
looks_like_boolean: true
check_mode: true
register: vpc_subnet_info
- name: assert tags haven't changed
ansible.builtin.assert:
that:
- vpc_subnet_info is not changed
- name: test idempotence adding a tag that looks like a boolean
amazon.aws.ec2_vpc_subnet:
cidr: "{{ subnet_cidr }}"
vpc_id: "{{ vpc_result.vpc.id }}"
state: present
purge_tags: false
tags:
looks_like_boolean: true
register: vpc_subnet_info
- name: assert tags haven't changed
ansible.builtin.assert:
that:
- vpc_subnet_info is not changed
always:
################################################
# TEARDOWN STARTS HERE
################################################
- name: tidy up subnet
amazon.aws.ec2_vpc_subnet:
cidr: "{{ subnet_cidr }}"
vpc_id: "{{ vpc_result.vpc.id }}"
state: absent
- name: tidy up VPC
amazon.aws.ec2_vpc_net:
name: "{{ resource_prefix }}-vpc"
state: absent
cidr_block: "{{ vpc_cidr }}"