Debian Codegraph @

ansible_collections/amazon/aws/tests/integration/targets/ec2_launch_template/tasks/versions.yml

raw
1 ---
2 - name: Test launch template versioning
3 vars:
4 test_launch_template_name: "{{ resource_prefix }}-versioning"
5 block:
6 # =====================================================================
7 # Create the launch template
8 # =====================================================================
9 - name: Create a launch template (check mode)
10 amazon.aws.ec2_launch_template:
11 name: "{{ test_launch_template_name }}"
12 image_id: "{{ ec2_ami_id }}"
13 tags:
14 TestId: "{{ resource_prefix }}"
15 instance_type: c4.large
16 register: _create_check
17 check_mode: true
18
19 - name: Read launch template information
20 amazon.aws.ec2_launch_template_info:
21 filters:
22 launch-template-name: "{{ test_launch_template_name }}"
23 register: _template_info
24
25 - name: Ensure module reported changed while the template was not created
26 ansible.builtin.assert:
27 that:
28 - _create_check is changed
29 - '"default_version" not in _create_check'
30 - '"latest_version" not in _create_check'
31 - _template_info.launch_templates | length == 0
32
33 - name: Create a launch template
34 amazon.aws.ec2_launch_template:
35 name: "{{ test_launch_template_name }}"
36 image_id: "{{ ec2_ami_id }}"
37 tags:
38 TestId: "{{ resource_prefix }}"
39 instance_type: c4.large
40 register: _create
41
42 - name: Read launch template information
43 amazon.aws.ec2_launch_template_info:
44 launch_template_ids:
45 - "{{ _create.template.launch_template_id }}"
46 register: _template_info
47
48 - name: Ensure the launch template was created with the right version
49 ansible.builtin.assert:
50 that:
51 - _create is changed
52 - _create.default_version == 1
53 - _create.latest_version == 1
54 - _template_info.launch_templates | length == 1
55 - _template_info.launch_templates[0].default_version_number == 1
56 - _template_info.launch_templates[0].latest_version_number == 1
57 - _template_info.launch_templates[0].versions | length == 1
58 - _template_info.launch_templates[0].versions.0.launch_template_data.image_id == ec2_ami_id
59 - _template_info.launch_templates[0].versions.0.launch_template_data.instance_type == "c4.large"
60
61 - name: Create the same launch template once again
62 amazon.aws.ec2_launch_template:
63 name: "{{ test_launch_template_name }}"
64 image_id: "{{ ec2_ami_id }}"
65 tags:
66 TestId: "{{ resource_prefix }}"
67 instance_type: c4.large
68 register: _create_idempotency
69
70 - name: Read launch template information
71 amazon.aws.ec2_launch_template_info:
72 filters:
73 launch-template-name: "{{ test_launch_template_name }}"
74 register: _template_info
75
76 - name: Ensure the module did not reported change (idempotency)
77 ansible.builtin.assert:
78 that:
79 - _create_idempotency is not changed
80 - _create.default_version == 1
81 - _create.latest_version == 1
82 - _template_info.launch_templates | length == 1
83 - _template_info.launch_templates[0].default_version_number == 1
84 - _template_info.launch_templates[0].latest_version_number == 1
85 - _template_info.launch_templates[0].versions | length == 1
86 - _template_info.launch_templates[0].versions.0.launch_template_data.image_id == ec2_ami_id
87 - _template_info.launch_templates[0].versions.0.launch_template_data.instance_type == "c4.large"
88
89 # =====================================================================
90 # Create a new version of the launch template (set first version as default)
91 # =====================================================================
92 - name: Create a new version of the launch template (check mode)
93 amazon.aws.ec2_launch_template:
94 name: "{{ test_launch_template_name }}"
95 default_version: 1
96 image_id: "{{ ec2_ami_id }}"
97 tags:
98 TestId: "{{ resource_prefix }}"
99 instance_type: m5.large
100 register: _update_check
101 check_mode: true
102
103 - name: Read launch template information
104 amazon.aws.ec2_launch_template_info:
105 filters:
106 launch-template-name: "{{ test_launch_template_name }}"
107 register: _template_info
108
109 - name: Ensure the module reported change in check mode
110 ansible.builtin.assert:
111 that:
112 - _update_check is changed
113 - _template_info.launch_templates | length == 1
114 - _template_info.launch_templates[0].default_version_number == 1
115 - _template_info.launch_templates[0].latest_version_number == 1
116 - _template_info.launch_templates[0].versions | length == 1
117
118 - name: Create a new version of the launch template
119 amazon.aws.ec2_launch_template:
120 name: "{{ test_launch_template_name }}"
121 default_version: 1
122 image_id: "{{ ec2_ami_id }}"
123 tags:
124 TestId: "{{ resource_prefix }}"
125 instance_type: m5.large
126 register: _update
127
128 - name: Read launch template information
129 amazon.aws.ec2_launch_template_info:
130 filters:
131 launch-template-name: "{{ test_launch_template_name }}"
132 register: _template_info
133
134 - name: Ensure the launch template latest version has changed
135 ansible.builtin.assert:
136 that:
137 - _update is changed
138 - _update.default_version == 1
139 - _update.latest_version == 2
140 - _template_info.launch_templates | length == 1
141 - _template_info.launch_templates[0].default_version_number == 1
142 - _template_info.launch_templates[0].latest_version_number == 2
143 - _template_info.launch_templates[0].versions | length == 2
144 - created_template.launch_template_data.image_id == ec2_ami_id
145 - created_template.launch_template_data.instance_type == "m5.large"
146 vars:
147 created_template: "{{ _template_info.launch_templates[0].versions | selectattr('version_number', 'equalto', 2) | first }}"
148
149 - name: Create a new version of the launch template (idempotency)
150 amazon.aws.ec2_launch_template:
151 name: "{{ test_launch_template_name }}"
152 default_version: 1
153 image_id: "{{ ec2_ami_id }}"
154 tags:
155 TestId: "{{ resource_prefix }}"
156 instance_type: m5.large
157 register: _update_idempotency
158
159 - name: Read launch template information
160 amazon.aws.ec2_launch_template_info:
161 filters:
162 launch-template-name: "{{ test_launch_template_name }}"
163 register: _template_info
164
165 - name: Ensure the module did not reported change (idempotency)
166 ansible.builtin.assert:
167 that:
168 - _update_idempotency is not changed
169 - _update_idempotency.default_version == 1
170 - _update_idempotency.latest_version == 2
171 - _template_info.launch_templates | length == 1
172 - _template_info.launch_templates[0].default_version_number == 1
173 - _template_info.launch_templates[0].latest_version_number == 2
174 - _template_info.launch_templates[0].versions | length == 2
175
176 # =====================================================================
177 # Set the latest version of the launch template as default
178 # =====================================================================
179 - name: Set the latest version of the launch template as default (check mode)
180 amazon.aws.ec2_launch_template:
181 name: "{{ test_launch_template_name }}"
182 default_version: latest
183 image_id: "{{ ec2_ami_id }}"
184 tags:
185 TestId: "{{ resource_prefix }}"
186 instance_type: m5.large
187 register: _set_version_check
188 check_mode: true
189
190 - name: Read launch template information
191 amazon.aws.ec2_launch_template_info:
192 filters:
193 launch-template-name: "{{ test_launch_template_name }}"
194 register: _template_info
195
196 - name: Ensure the module reported change in check mode
197 ansible.builtin.assert:
198 that:
199 - _set_version_check is changed
200 - _template_info.launch_templates | length == 1
201 - _template_info.launch_templates[0].default_version_number == 1
202 - _template_info.launch_templates[0].latest_version_number == 2
203 - _template_info.launch_templates[0].versions | length == 2
204
205 - name: Set the latest version of the launch template as default
206 amazon.aws.ec2_launch_template:
207 name: "{{ test_launch_template_name }}"
208 default_version: latest
209 image_id: "{{ ec2_ami_id }}"
210 tags:
211 TestId: "{{ resource_prefix }}"
212 instance_type: m5.large
213 register: _set_version
214
215 - name: Read launch template information
216 amazon.aws.ec2_launch_template_info:
217 filters:
218 launch-template-name: "{{ test_launch_template_name }}"
219 register: _template_info
220
221 - name: Ensure the launch template latest version has changed
222 ansible.builtin.assert:
223 that:
224 - _set_version is changed
225 - _set_version.default_version == 2
226 - _set_version.latest_version == 2
227 - _template_info.launch_templates | length == 1
228 - _template_info.launch_templates[0].default_version_number == 2
229 - _template_info.launch_templates[0].latest_version_number == 2
230 - _template_info.launch_templates[0].versions | length == 2
231 - created_template.launch_template_data.image_id == ec2_ami_id
232 - created_template.launch_template_data.instance_type == "m5.large"
233 vars:
234 created_template: "{{ _template_info.launch_templates[0].versions | selectattr('version_number', 'equalto', 2) | first }}"
235
236 - name: Set the latest version of the launch template as default (idempotency)
237 amazon.aws.ec2_launch_template:
238 name: "{{ test_launch_template_name }}"
239 default_version: latest
240 image_id: "{{ ec2_ami_id }}"
241 tags:
242 TestId: "{{ resource_prefix }}"
243 instance_type: m5.large
244 register: _set_version_idempotency
245
246 - name: Read launch template information
247 amazon.aws.ec2_launch_template_info:
248 filters:
249 launch-template-name: "{{ test_launch_template_name }}"
250 register: _template_info
251
252 - name: Ensure the module did not reported change (idempotency)
253 ansible.builtin.assert:
254 that:
255 - _set_version_idempotency is not changed
256 - _set_version_idempotency.default_version == 2
257 - _set_version_idempotency.latest_version == 2
258 - _template_info.launch_templates[0].default_version_number == 2
259 - _template_info.launch_templates[0].latest_version_number == 2
260 - _template_info.launch_templates[0].versions | length == 2
261
262 # =====================================================================
263 # Create another version
264 # =====================================================================
265 - name: Create a new launch template version (check mode)
266 amazon.aws.ec2_launch_template:
267 name: "{{ test_launch_template_name }}"
268 image_id: "{{ ec2_ami_id }}"
269 tags:
270 TestId: "{{ resource_prefix }}"
271 instance_type: t3.medium
272 register: _another_version_check
273 check_mode: true
274
275 - name: Read launch template information
276 amazon.aws.ec2_launch_template_info:
277 launch_template_ids:
278 - "{{ _create.template.launch_template_id }}"
279 register: _template_info
280
281 - name: Ensure the module reported change in check_mode
282 ansible.builtin.assert:
283 that:
284 - _another_version_check is changed
285 - _template_info.launch_templates | length == 1
286 - _template_info.launch_templates[0].default_version_number == 2
287 - _template_info.launch_templates[0].latest_version_number == 2
288 - _template_info.launch_templates[0].versions | length == 2
289
290 - name: Create a new launch template version
291 amazon.aws.ec2_launch_template:
292 name: "{{ test_launch_template_name }}"
293 image_id: "{{ ec2_ami_id }}"
294 tags:
295 TestId: "{{ resource_prefix }}"
296 instance_type: t3.medium
297 register: _another_version
298
299 - name: Read launch template information
300 amazon.aws.ec2_launch_template_info:
301 launch_template_ids:
302 - "{{ _create.template.launch_template_id }}"
303 register: _template_info
304
305 - name: Ensure the launch template latest version has changed
306 ansible.builtin.assert:
307 that:
308 - _another_version is changed
309 - _another_version.default_version == 3
310 - _another_version.latest_version == 3
311 - _template_info.launch_templates | length == 1
312 - _template_info.launch_templates[0].default_version_number == 3
313 - _template_info.launch_templates[0].latest_version_number == 3
314 - _template_info.launch_templates[0].versions | length == 3
315 - created_template.launch_template_data.image_id == ec2_ami_id
316 - created_template.launch_template_data.instance_type == "t3.medium"
317 vars:
318 created_template: "{{ _template_info.launch_templates[0].versions | selectattr('version_number', 'equalto', 3) | first }}"
319
320 - name: Create a new launch template version (idempotency)
321 amazon.aws.ec2_launch_template:
322 name: "{{ test_launch_template_name }}"
323 image_id: "{{ ec2_ami_id }}"
324 tags:
325 TestId: "{{ resource_prefix }}"
326 instance_type: t3.medium
327 register: _another_version_idempotency
328
329 - name: Read launch template information
330 amazon.aws.ec2_launch_template_info:
331 launch_template_ids:
332 - "{{ _create.template.launch_template_id }}"
333 register: _template_info
334
335 - name: Ensure the module did not reported change (idempotency)
336 ansible.builtin.assert:
337 that:
338 - _another_version_idempotency is not changed
339 - _another_version_idempotency.default_version == 3
340 - _another_version_idempotency.latest_version == 3
341 - _template_info.launch_templates | length == 1
342 - _template_info.launch_templates[0].default_version_number == 3
343 - _template_info.launch_templates[0].latest_version_number == 3
344 - _template_info.launch_templates[0].versions | length == 3
345
346 # =====================================================================
347 # Create another version based on an old version
348 # =====================================================================
349 - name: Create new template version based on an old version (check mode)
350 amazon.aws.ec2_launch_template:
351 name: "{{ test_launch_template_name }}"
352 cpu_options:
353 core_count: 1
354 threads_per_core: 1
355 source_version: 1
356 register: _version_based_on_old_version_check
357 check_mode: true
358
359 - name: Read launch template information
360 amazon.aws.ec2_launch_template_info:
361 launch_template_ids:
362 - "{{ _create.template.launch_template_id }}"
363 register: _template_info
364
365 - name: Ensure module reported change in check mode
366 ansible.builtin.assert:
367 that:
368 - _version_based_on_old_version_check is changed
369 - _template_info.launch_templates | length == 1
370 - _template_info.launch_templates[0].default_version_number == 3
371 - _template_info.launch_templates[0].latest_version_number == 3
372 - _template_info.launch_templates[0].versions | length == 3
373
374 - name: Create new template version based on an old version
375 amazon.aws.ec2_launch_template:
376 name: "{{ test_launch_template_name }}"
377 cpu_options:
378 core_count: 1
379 threads_per_core: 1
380 source_version: 1
381 register: _version_based_on_old_version
382
383 - name: Read launch template information
384 amazon.aws.ec2_launch_template_info:
385 launch_template_ids:
386 - "{{ _create.template.launch_template_id }}"
387 register: _template_info
388
389 - name: Ensure the new launch template has been created with the right options
390 ansible.builtin.assert:
391 that:
392 - _version_based_on_old_version is changed
393 - _version_based_on_old_version.default_version == 4
394 - _version_based_on_old_version.latest_version == 4
395 - _version_based_on_old_version.latest_template.launch_template_data.instance_type == "c4.large"
396 - _template_info.launch_templates | length == 1
397 - _template_info.launch_templates[0].default_version_number == 4
398 - _template_info.launch_templates[0].latest_version_number == 4
399 - _template_info.launch_templates[0].versions | length == 4
400 - created_template.launch_template_data.image_id == ec2_ami_id
401 - created_template.launch_template_data.cpu_options.core_count == 1
402 - created_template.launch_template_data.cpu_options.threads_per_core == 1
403 vars:
404 created_template: "{{ _template_info.launch_templates[0].versions | selectattr('version_number', 'equalto', 4) | first }}"
405
406 # =====================================================================
407 # Create another version with updated description
408 # =====================================================================
409 - name: Create a launch template version with another description (check mode)
410 amazon.aws.ec2_launch_template:
411 name: "{{ test_launch_template_name }}"
412 version_description: "Fix something."
413 register: _version_description_check
414 check_mode: true
415
416 - name: Read launch template information
417 amazon.aws.ec2_launch_template_info:
418 launch_template_ids:
419 - "{{ _create.template.launch_template_id }}"
420 register: _template_info
421
422 - name: Ensure module reported change in check mode
423 ansible.builtin.assert:
424 that:
425 - _version_description_check is changed
426 - _template_info.launch_templates | length == 1
427 - _template_info.launch_templates[0].default_version_number == 4
428 - _template_info.launch_templates[0].latest_version_number == 4
429 - _template_info.launch_templates[0].versions | length == 4
430
431 - name: Create a launch template version with another description
432 amazon.aws.ec2_launch_template:
433 name: "{{ test_launch_template_name }}"
434 version_description: "Fix something."
435 register: _version_description
436
437 - name: Read launch template information
438 amazon.aws.ec2_launch_template_info:
439 launch_template_ids:
440 - "{{ _create.template.launch_template_id }}"
441 register: _template_info
442
443 - name: Ensure module reported change
444 ansible.builtin.assert:
445 that:
446 - _version_description is changed
447 - _version_description.default_version == 5
448 - _version_description.latest_version == 5
449 - _version_description.latest_template.version_description == "Fix something."
450 - _template_info.launch_templates | length == 1
451 - _template_info.launch_templates[0].default_version_number == 5
452 - _template_info.launch_templates[0].latest_version_number == 5
453 - _template_info.launch_templates[0].versions | length == 5
454 - created_template.version_description == "Fix something."
455 vars:
456 created_template: "{{ _template_info.launch_templates[0].versions | selectattr('version_number', 'equalto', 5) | first }}"
457
458 always:
459 - name: Delete the template
460 amazon.aws.ec2_launch_template:
461 name: "{{ test_launch_template_name }}"
462 state: absent
463 ignore_errors: true