Debian Codegraph @

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

raw
1 ---
2 - module_defaults:
3 group/aws:
4 access_key: "{{ aws_access_key }}"
5 secret_key: "{{ aws_secret_key }}"
6 session_token: "{{ security_token | default(omit) }}"
7 region: "{{ aws_region }}"
8
9 block:
10 # ============================================================
11
12 - name: Test without any parameters
13 amazon.aws.ec2_vpc_nacl:
14 register: result
15 ignore_errors: true
16
17 - name: Assert required parameters
18 ansible.builtin.assert:
19 that:
20 - result.failed
21 - "result.msg == 'one of the following is required: name, nacl_id'"
22
23 - name: Get network ACL info without any parameters
24 amazon.aws.ec2_vpc_nacl_info:
25 register: nacl_facts
26
27 - name: Assert we don't error
28 ansible.builtin.assert:
29 that:
30 - nacl_facts is succeeded
31
32 - name: Get network ACL info with invalid ID
33 amazon.aws.ec2_vpc_nacl_info:
34 nacl_ids:
35 - "acl-000000000000"
36 register: nacl_facts
37 ignore_errors: true
38
39 - name: Assert message mentions missing ACLs
40 ansible.builtin.assert:
41 that:
42 - nacl_facts is failed
43 - '"does not exist" in nacl_facts.msg'
44 - '"One or more" not in nacl_facts.msg'
45
46 - name: Get network multiple ACLs info with invalid ID
47 amazon.aws.ec2_vpc_nacl_info:
48 nacl_ids:
49 - 'acl-000000000000'
50 - 'acl-000000000001'
51 register: nacl_facts
52 ignore_errors: true
53
54 - name: Assert message mentions missing ACLs
55 ansible.builtin.assert:
56 that:
57 - nacl_facts is failed
58 - '"does not exist" in nacl_facts.msg'
59 - '"One or more" in nacl_facts.msg'
60
61 - name: Get network ACL info with filters
62 amazon.aws.ec2_vpc_nacl_info:
63 filters:
64 default: false
65 register: nacl_facts
66
67 - name: Assert error is not returned
68 ansible.builtin.assert:
69 that:
70 - nacl_facts is succeeded
71 # ============================================================
72
73 - name: Fetch AZ availability
74 amazon.aws.aws_az_info:
75 register: az_info
76
77 - name: Assert that we have multiple AZs available to us
78 ansible.builtin.assert:
79 that: az_info.availability_zones | length >= 2
80
81 - name: Pick AZs
82 ansible.builtin.set_fact:
83 az_one: "{{ az_info.availability_zones[0].zone_name }}"
84 az_two: "{{ az_info.availability_zones[1].zone_name }}"
85
86 # ============================================================
87
88 - name: Create a VPC
89 amazon.aws.ec2_vpc_net:
90 cidr_block: "{{ vpc_cidr }}"
91 name: "{{ vpc_name }}"
92 state: present
93 register: vpc
94
95 - name: Save VPC ID for later
96 ansible.builtin.set_fact:
97 vpc_id: "{{ vpc.vpc.id }}"
98
99 - name: Create subnets
100 amazon.aws.ec2_vpc_subnet:
101 cidr: "{{ item.cidr }}"
102 az: "{{ item.az }}"
103 vpc_id: "{{ vpc_id }}"
104 state: present
105 tags:
106 Name: "{{ item.name }}"
107 with_items:
108 - cidr: "{{ subnet_1 }}"
109 az: "{{ az_one }}"
110 name: "{{ subnet_name }}-1"
111 - cidr: "{{ subnet_2 }}"
112 az: "{{ az_two }}"
113 name: "{{ subnet_name }}-2"
114 - cidr: "{{ subnet_3 }}"
115 az: "{{ az_one }}"
116 name: "{{ subnet_name }}-3"
117 - cidr: "{{ subnet_4 }}"
118 az: "{{ az_two }}"
119 name: "{{ subnet_name }}-4"
120 register: subnets
121
122 - name: Set helpful facts about subnets
123 ansible.builtin.set_fact:
124 subnet_ids: "{{ subnets | community.general.json_query('results[*].subnet.id') }}"
125 subnet_names: "{{ subnets | community.general.json_query('results[*].subnet.tags.Name') }}"
126
127 - name: Create VPC for IPv6 tests
128 amazon.aws.ec2_vpc_net:
129 cidr_block: "{{ vpc_ipv6_cidr }}"
130 name: "{{ vpc_ipv6_name }}"
131 state: present
132 ipv6_cidr: true
133 register: vpc_result
134
135 - name: Set helpful IPv6 facts
136 ansible.builtin.set_fact:
137 vpc_ipv6_id: "{{ vpc_result.vpc.id }}"
138 vpc_ipv6_cidr_v6: "{{ _ipv6_cidr }}"
139 subnet_ipv6: "{{ _ipv6_cidr | regex_replace('::/56', '::/64') }}"
140 vars:
141 _ipv6_cidr: "{{ vpc_result.vpc.ipv6_cidr_block_association_set[0].ipv6_cidr_block }}"
142
143 - name: Create subnet with IPv6
144 amazon.aws.ec2_vpc_subnet:
145 cidr: "{{ vpc_ipv6_cidr }}"
146 vpc_id: "{{ vpc_ipv6_id }}"
147 ipv6_cidr: "{{ subnet_ipv6 }}"
148 state: present
149 tags:
150 Name: "{{ subnet_name }}-ipv6"
151
152 # ============================================================
153 - name: Run individual tasks
154 ansible.builtin.include_tasks: "tasks/{{ item }}.yml"
155 with_items:
156 - subnet_ids
157 - subnet_names
158 - tags
159 - ingress_and_egress
160 - ipv6
161
162 # ============================================================
163
164 always:
165 - name: Remove network ACL
166 amazon.aws.ec2_vpc_nacl:
167 vpc_id: "{{ vpc_id }}"
168 name: "{{ nacl_name }}"
169 state: absent
170 register: removed_acl
171 ignore_errors: true
172
173 - name: Remove subnets
174 amazon.aws.ec2_vpc_subnet:
175 cidr: "{{ item.cidr }}"
176 vpc_id: "{{ item.vpc_id | default(vpc_id) }}"
177 state: absent
178 with_items:
179 - cidr: "{{ subnet_1 }}"
180 - cidr: "{{ subnet_2 }}"
181 - cidr: "{{ subnet_3 }}"
182 - cidr: "{{ subnet_4 }}"
183 - cidr: "{{ vpc_ipv6_cidr }}"
184 vpc_id: "{{ vpc_ipv6_id }}"
185 ignore_errors: true
186 register: removed_subnets
187
188 - name: Remove the VPCs
189 amazon.aws.ec2_vpc_net:
190 vpc_id: "{{ item }}"
191 state: absent
192 ignore_errors: true
193 register: removed_vpc
194 with_items:
195 - "{{ vpc_id }}"
196 - "{{ vpc_ipv6_id }}"
197
198 # ============================================================