Debian Codegraph @

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

raw symbols SCIP
1 ---
2 - name: "ec2_asg_scheduled_action integration tests"
3 collections:
4 - amazon.aws
5 - community.aws
6 module_defaults:
7 group/aws:
8 access_key: "{{ aws_access_key }}"
9 secret_key: "{{ aws_secret_key }}"
10 session_token: "{{ security_token | default(omit) }}"
11 region: "{{ aws_region }}"
12 block:
13 ## Set up the testing dependencies: VPC, subnet, security group, and launch configuration
14 - name: Create VPC for use in testing
15 ec2_vpc_net:
16 name: "{{ resource_prefix }}-vpc"
17 cidr_block: 10.55.77.0/24
18 tenancy: default
19 register: testing_vpc
20
21 - name: Create subnet for use in testing
22 ec2_vpc_subnet:
23 state: present
24 vpc_id: "{{ testing_vpc.vpc.id }}"
25 cidr: 10.55.77.0/24
26 az: "{{ aws_region }}a"
27 resource_tags:
28 Name: "{{ resource_prefix }}-subnet"
29 register: testing_subnet
30
31 - name: create a security group with the vpc created in the ec2_setup
32 ec2_security_group:
33 name: "{{ resource_prefix }}-sg"
34 description: a security group for ansible tests
35 vpc_id: "{{ testing_vpc.vpc.id }}"
36 rules:
37 - proto: tcp
38 from_port: 22
39 to_port: 22
40 cidr_ip: 0.0.0.0/0
41 - proto: tcp
42 from_port: 80
43 to_port: 80
44 cidr_ip: 0.0.0.0/0
45 register: sg
46
47 - name: ensure launch configs exist
48 autoscaling_launch_config:
49 name: "{{ resource_prefix }}-lc"
50 assign_public_ip: true
51 image_id: "{{ ec2_ami_id }}"
52 security_groups: "{{ sg.group_id }}"
53 instance_type: t3.micro
54
55 - name: Create ASG ready
56 autoscaling_group:
57 name: "{{ resource_prefix }}-asg"
58 launch_config_name: "{{ resource_prefix }}-lc"
59 desired_capacity: 1
60 min_size: 1
61 max_size: 2
62 vpc_zone_identifier: "{{ testing_subnet.subnet.id }}"
63 state: present
64 wait_for_instances: yes
65 register: output
66
67 - assert:
68 that:
69 - "output.viable_instances == 1"
70
71 ## Create minimal basic scheduled action
72 - name: Create basic scheduled_action - check_mode
73 autoscaling_scheduled_action:
74 autoscaling_group_name: "{{ resource_prefix }}-asg"
75 scheduled_action_name: "{{ resource_prefix }}-test"
76 start_time: 2027 November 9 08:00 UTC
77 recurrence: 40 22 * * 1-5
78 desired_capacity: 2
79 state: present
80 register: scheduled_action
81 check_mode: True
82
83 - name: Check results - Create basic scheduled_action - check_mode
84 assert:
85 that:
86 - scheduled_action is successful
87 - scheduled_action is changed
88
89 - name: Create basic scheduled_action
90 autoscaling_scheduled_action:
91 autoscaling_group_name: "{{ resource_prefix }}-asg"
92 scheduled_action_name: "{{ resource_prefix }}-test"
93 start_time: 2027 November 9 08:00 UTC
94 recurrence: 40 22 * * 1-5
95 desired_capacity: 2
96 state: present
97 register: scheduled_action
98
99 - name: Check results - Create basic scheduled_action
100 assert:
101 that:
102 - scheduled_action is successful
103 - scheduled_action is changed
104 - scheduled_action.scheduled_action_name == resource_prefix ~ '-test'
105 - scheduled_action.desired_capacity == 2
106
107 - name: Create basic scheduled_action - idempotent
108 autoscaling_scheduled_action:
109 autoscaling_group_name: "{{ resource_prefix }}-asg"
110 scheduled_action_name: "{{ resource_prefix }}-test"
111 start_time: 2027 November 9 08:00 UTC
112 recurrence: 40 22 * * 1-5
113 desired_capacity: 2
114 state: present
115 register: scheduled_action
116
117 - name: Check results - Create advanced scheduled_action - idempotent
118 assert:
119 that:
120 - scheduled_action is successful
121 - scheduled_action is not changed
122
123 ## Update minimal basic scheduled action
124 - name: Update basic scheduled_action - check_mode
125 autoscaling_scheduled_action:
126 autoscaling_group_name: "{{ resource_prefix }}-asg"
127 scheduled_action_name: "{{ resource_prefix }}-test"
128 start_time: 2027 November 9 08:00 UTC
129 recurrence: 40 22 * * 1-5
130 desired_capacity: 3
131 min_size: 3
132 state: present
133 register: scheduled_action
134 check_mode: True
135
136 - name: Check results - Update basic scheduled_action - check_mode
137 assert:
138 that:
139 - scheduled_action is successful
140 - scheduled_action is changed
141
142 - name: Update basic scheduled_action
143 autoscaling_scheduled_action:
144 autoscaling_group_name: "{{ resource_prefix }}-asg"
145 scheduled_action_name: "{{ resource_prefix }}-test"
146 start_time: 2027 November 9 08:00 UTC
147 recurrence: 40 22 * * 1-5
148 desired_capacity: 3
149 min_size: 3
150 state: present
151 register: scheduled_action
152
153 - name: Check results - Update basic scheduled_action
154 assert:
155 that:
156 - scheduled_action is successful
157 - scheduled_action is changed
158 - scheduled_action.scheduled_action_name == resource_prefix ~ '-test'
159 - scheduled_action.desired_capacity == 3
160 - scheduled_action.min_size == 3
161
162 - name: Update basic scheduled_action - idempotent
163 autoscaling_scheduled_action:
164 autoscaling_group_name: "{{ resource_prefix }}-asg"
165 scheduled_action_name: "{{ resource_prefix }}-test"
166 start_time: 2027 November 9 08:00 UTC
167 recurrence: 40 22 * * 1-5
168 desired_capacity: 3
169 min_size: 3
170 state: present
171 register: scheduled_action
172
173 - name: Check results - Update advanced scheduled_action - idempotent
174 assert:
175 that:
176 - scheduled_action is successful
177 - scheduled_action is not changed
178
179 ## Create advanced scheduled action
180 - name: Create advanced scheduled_action - check_mode
181 autoscaling_scheduled_action:
182 autoscaling_group_name: "{{ resource_prefix }}-asg"
183 scheduled_action_name: "{{ resource_prefix }}-test"
184 start_time: 2027 November 9 09:00 UTC
185 end_time: 2027 November 9 10:00 UTC
186 time_zone: Europe/London
187 recurrence: 40 22 * * 1-5
188 min_size: 2
189 max_size: 5
190 desired_capacity: 2
191 state: present
192 register: advanced_scheduled_action
193 check_mode: True
194
195 - name: Check results - Create basic scheduled_action - check_mode
196 assert:
197 that:
198 - advanced_scheduled_action is successful
199 - advanced_scheduled_action is changed
200
201 - name: Create advanced scheduled_action
202 autoscaling_scheduled_action:
203 autoscaling_group_name: "{{ resource_prefix }}-asg"
204 scheduled_action_name: "{{ resource_prefix }}-test1"
205 start_time: 2027 November 9 09:00 UTC
206 end_time: 2027 November 9 10:00 UTC
207 time_zone: Europe/London
208 recurrence: 40 22 * * 1-5
209 min_size: 2
210 max_size: 5
211 desired_capacity: 2
212 state: present
213 register: advanced_scheduled_action
214
215 - name: Check results - Create advanced scheduled_action
216 assert:
217 that:
218 - advanced_scheduled_action is successful
219 - advanced_scheduled_action is changed
220 - advanced_scheduled_action.scheduled_action_name == resource_prefix ~ '-test1'
221 - advanced_scheduled_action.desired_capacity == 2
222 - advanced_scheduled_action.min_size == 2
223 - advanced_scheduled_action.max_size == 5
224 - advanced_scheduled_action.time_zone == "Europe/London"
225
226 - name: Create advanced scheduled_action - idempotent
227 autoscaling_scheduled_action:
228 autoscaling_group_name: "{{ resource_prefix }}-asg"
229 scheduled_action_name: "{{ resource_prefix }}-test1"
230 start_time: 2027 November 9 09:00 UTC
231 end_time: 2027 November 9 10:00 UTC
232 time_zone: Europe/London
233 recurrence: 40 22 * * 1-5
234 min_size: 2
235 max_size: 5
236 desired_capacity: 2
237 state: present
238 register: advanced_scheduled_action
239
240 - name: Check results - Create basic scheduled_action - idempotent
241 assert:
242 that:
243 - advanced_scheduled_action is successful
244 - advanced_scheduled_action is not changed
245
246 ## Delete scheduled action
247 - name: Delete scheduled_action - check_mode
248 autoscaling_scheduled_action:
249 autoscaling_group_name: "{{ resource_prefix }}-asg"
250 scheduled_action_name: "{{ resource_prefix }}-test1"
251 state: absent
252 register: scheduled_action_deletion
253 check_mode: True
254
255 - name: Delete scheduled_action - check_mode
256 assert:
257 that:
258 - scheduled_action_deletion is successful
259 - scheduled_action_deletion is changed
260
261 - name: Delete scheduled_action
262 autoscaling_scheduled_action:
263 autoscaling_group_name: "{{ resource_prefix }}-asg"
264 scheduled_action_name: "{{ resource_prefix }}-test1"
265 state: absent
266 register: scheduled_action_deletion
267
268 - name: Delete scheduled_action
269 assert:
270 that:
271 - scheduled_action_deletion is successful
272 - scheduled_action_deletion is changed
273
274 - name: Delete scheduled_action - idempotent
275 autoscaling_scheduled_action:
276 autoscaling_group_name: "{{ resource_prefix }}-asg"
277 scheduled_action_name: "{{ resource_prefix }}-test1"
278 state: absent
279 register: scheduled_action_deletion
280
281 - name: Delete scheduled_action - idempotent
282 assert:
283 that:
284 - scheduled_action_deletion is successful
285 - scheduled_action_deletion is not changed
286 always:
287 - name: Remove ASG
288 autoscaling_group:
289 name: "{{ resource_prefix }}-asg"
290 state: absent
291 register: removed
292 until: removed is not failed
293 ignore_errors: yes
294 retries: 10
295
296 # Remove the testing dependencies
297 - name: Remove launch configs
298 autoscaling_launch_config:
299 name: "{{ resource_prefix }}-lc"
300 state: absent
301 register: removed
302 until: removed is not failed
303 ignore_errors: yes
304 retries: 10
305
306 - name: Remove the security group
307 ec2_security_group:
308 name: "{{ resource_prefix }}-sg"
309 description: a security group for ansible tests
310 vpc_id: "{{ testing_vpc.vpc.id }}"
311 state: absent
312 register: removed
313 until: removed is not failed
314 ignore_errors: yes
315 retries: 10
316
317 - name: Remove the subnet
318 ec2_vpc_subnet:
319 state: absent
320 vpc_id: "{{ testing_vpc.vpc.id }}"
321 cidr: 10.55.77.0/24
322 register: removed
323 until: removed is not failed
324 ignore_errors: yes
325 retries: 10
326
327 - name: Remove the VPC
328 ec2_vpc_net:
329 name: "{{ resource_prefix }}-vpc"
330 cidr_block: 10.55.77.0/24
331 state: absent
332 register: removed
333 until: removed is not failed
334 ignore_errors: yes
335 retries: 10