Debian Codegraph @

ansible_collections/amazon/aws/plugins/modules/ec2_launch_template_info.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: Ansible Project
5 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 DOCUMENTATION = r"""
8 ---
9 module: ec2_launch_template_info
10 version_added: 9.0.0
11 short_description: Gather information about launch templates and versions
12 description:
13 - Gather information about launch templates.
14 author:
15 - Aubin Bikouo (@abikouo)
16 options:
17 launch_template_ids:
18 description: The IDs of the launch templates.
19 type: list
20 elements: str
21 filters:
22 description:
23 - A dict of filters to apply. Each dict item consists of a filter key and a filter value.
24 - See U(https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeLaunchTemplates.html) for possible filters.
25 - Filter names and values are case sensitive.
26 type: dict
27 default: {}
28
29 extends_documentation_fragment:
30 - amazon.aws.common.modules
31 - amazon.aws.region.modules
32 - amazon.aws.boto3
33 """
34
35 EXAMPLES = r"""
36 # Note: These examples do not set authentication details, see the AWS Guide for details.
37
38 - name: Gather information about a launch template
39 amazon.aws.ec2_launch_template_info:
40 launch_template_ids:
41 - 'lt-01238c059e3466abc'
42
43 - name: Gather information launch template using name
44 amazon.aws.ec2_launch_template_info:
45 filters:
46 launch-template-name: my-test-launch-template
47 """
48
49 RETURN = r"""
50 launch_templates:
51 description: A list of launch templates.
52 returned: always
53 type: list
54 elements: dict
55 contains:
56 launch_template_id:
57 description: The ID of the launch template.
58 type: str
59 returned: always
60 launch_template_name:
61 description: The name of the launch template.
62 type: str
63 returned: always
64 create_time:
65 description: The time launch template was created.
66 type: str
67 returned: always
68 created_by:
69 description: The principal that created the launch template.
70 type: str
71 returned: always
72 default_version_number:
73 description: The version number of the default version of the launch template.
74 type: int
75 returned: always
76 latest_version_number:
77 description: The version number of the latest version of the launch template.
78 type: int
79 returned: always
80 tags:
81 description: A dictionary of tags assigned to image.
82 returned: when AMI is created or already exists
83 type: dict
84 sample: {
85 "Env": "devel",
86 "Name": "nat-server"
87 }
88 versions:
89 description: All available versions of the launch template.
90 type: list
91 elements: dict
92 returned: always
93 contains:
94 launch_template_id:
95 description: The ID of the launch template.
96 type: str
97 returned: always
98 launch_template_name:
99 description: The name of the launch template.
100 type: str
101 returned: always
102 create_time:
103 description: The time the version was created.
104 type: str
105 returned: always
106 created_by:
107 description: The principal that created the version.
108 type: str
109 returned: always
110 default_version:
111 description: Indicates whether the version is the default version.
112 type: bool
113 returned: always
114 version_number:
115 description: The version number.
116 type: int
117 returned: always
118 version_description:
119 description: The description for the version.
120 type: str
121 returned: always
122 launch_template_data:
123 description: Information about the launch template.
124 returned: always
125 type: dict
126 contains:
127 kernel_id:
128 description:
129 - The ID of the kernel.
130 returned: if applicable
131 type: str
132 image_id:
133 description: The ID of the AMI or a Systems Manager parameter.
134 type: str
135 returned: if applicable
136 instance_type:
137 description: The instance type.
138 type: str
139 returned: if applicable
140 key_name:
141 description: The name of the key pair.
142 type: str
143 returned: if applicable
144 monitoring:
145 description: The monitoring for the instance.
146 type: dict
147 returned: if applicable
148 contains:
149 enabled:
150 description: Indicates whether detailed monitoring is enabled. Otherwise, basic monitoring is enabled.
151 type: bool
152 returned: always
153 placement:
154 description: The placement of the instance.
155 type: dict
156 returned: if applicable
157 contains:
158 availability_zone:
159 description: The Availability Zone of the instance.
160 type: str
161 returned: if applicable
162 affinity:
163 description: The affinity setting for the instance on the Dedicated Host.
164 type: str
165 returned: if applicable
166 group_name:
167 description: The name of the placement group for the instance.
168 type: str
169 returned: if applicable
170 host_id:
171 description: The ID of the Dedicated Host for the instance.
172 type: str
173 returned: if applicable
174 tenancy:
175 description: The tenancy of the instance.
176 type: str
177 returned: if applicable
178 host_resource_group_arn:
179 description: The ARN of the host resource group in which to launch the instances.
180 type: str
181 returned: if applicable
182 partition_number:
183 description: The number of the partition the instance should launch in.
184 type: int
185 returned: if applicable
186 group_id:
187 description: The Group ID of the placement group.
188 type: str
189 returned: if applicable
190 ebs_optimized:
191 description:
192 - Indicates whether the instance is optimized for Amazon EBS I/O.
193 type: bool
194 returned: always
195 iam_instance_profile:
196 description:
197 - The IAM instance profile.
198 type: dict
199 returned: if application
200 contains:
201 arn:
202 description: The Amazon Resource Name (ARN) of the instance profile.
203 type: str
204 returned: always
205 name:
206 description: The name of the instance profile.
207 type: str
208 returned: always
209 block_device_mappings:
210 description: The block device mappings.
211 type: list
212 elements: dict
213 returned: if applicable
214 contains:
215 device_name:
216 description: The device name.
217 type: str
218 returned: always
219 virtual_name:
220 description: The virtual device name.
221 type: str
222 returned: always
223 ebs:
224 description: Information about the block device for an EBS volume.
225 type: str
226 returned: if applicable
227 contains:
228 encrypted:
229 description: Indicates whether the EBS volume is encrypted.
230 type: bool
231 returned: always
232 delete_on_termination:
233 description: Indicates whether the EBS volume is deleted on instance termination.
234 type: bool
235 returned: always
236 iops:
237 description: The number of I/O operations per second (IOPS) that the volume supports.
238 type: int
239 returned: always
240 kms_key_id:
241 description: The ARN of the Key Management Service (KMS) CMK used for encryption.
242 type: int
243 returned: always
244 snapshot_id:
245 description: The ID of the snapshot.
246 type: str
247 returned: always
248 volume_size:
249 description: The size of the volume, in GiB.
250 type: int
251 returned: always
252 volume_type:
253 description: The volume type.
254 type: str
255 returned: always
256 throughput:
257 description: The throughput that the volume supports, in MiB/s.
258 type: int
259 returned: always
260 no_device:
261 description: To omit the device from the block device mapping, specify an empty string.
262 type: str
263 network_interfaces:
264 description: The network interfaces.
265 type: list
266 elements: dict
267 returned: if applicable
268 contains:
269 associate_carrier_ip_address:
270 description: Indicates whether to associate a Carrier IP address with eth0 for a new network interface.
271 type: bool
272 returned: always
273 associate_public_ip_address:
274 description: Indicates whether to associate a public IPv4 address with eth0 for a new network interface.
275 type: bool
276 returned: always
277 delete_on_termination:
278 description: Indicates whether the network interface is deleted when the instance is terminated.
279 type: bool
280 returned: always
281 description:
282 description: A description for the network interface.
283 type: str
284 returned: always
285 device_index:
286 description: The device index for the network interface attachment.
287 type: int
288 returned: always
289 groups:
290 description: The IDs of one or more security groups.
291 type: list
292 elements: str
293 returned: if applicable
294 interface_type:
295 description: The type of network interface.
296 type: str
297 returned: always
298 ipv6_address_count:
299 description: The number of IPv6 addresses for the network interface.
300 type: int
301 returned: if applicable
302 ipv6_addresses:
303 description: The IPv6 addresses for the network interface.
304 returned: if applicable
305 type: list
306 elements: dict
307 contains:
308 ipv6_address:
309 description: The IPv6 address.
310 type: str
311 returned: always
312 is_primary_ipv6:
313 description: Determines if an IPv6 address associated with a network interface is the primary IPv6 address.
314 type: bool
315 returned: always
316 network_interface_id:
317 description: The ID of the network interface.
318 type: str
319 returned: always
320 private_ip_address:
321 description: The primary private IPv4 address of the network interface.
322 type: str
323 returned: if applicable
324 private_ip_addresses:
325 description: A list of private IPv4 addresses.
326 type: list
327 elements: str
328 returned: if applicable
329 contains:
330 primary:
331 description: Indicates whether the private IPv4 address is the primary private IPv4 address.
332 type: bool
333 returned: always
334 private_ip_address:
335 description: The private IPv4 address.
336 type: bool
337 returned: always
338 secondary_private_ip_address_count:
339 description: The number of secondary private IPv4 addresses for the network interface.
340 type: int
341 returned: if applicable
342 subnet_id:
343 description: The ID of the subnet for the network interface.
344 type: str
345 returned: always
346 network_card_index:
347 description: The index of the network card.
348 type: int
349 returned: if applicable
350 ipv4_prefixes:
351 description: A list of IPv4 prefixes assigned to the network interface.
352 type: list
353 elements: dict
354 returned: if applicable
355 contains:
356 ipv4_prefix:
357 description: The IPv4 delegated prefixes assigned to the network interface.
358 type: str
359 returned: always
360 ipv4_prefix_count:
361 description: The number of IPv4 prefixes that Amazon Web Services automatically assigned to the network interface.
362 type: int
363 returned: if applicable
364 ipv6_prefixes:
365 description: A list of IPv6 prefixes assigned to the network interface.
366 type: list
367 elements: dict
368 returned: if applicable
369 contains:
370 ipv6_prefix:
371 description: The IPv6 delegated prefixes assigned to the network interface.
372 type: str
373 returned: always
374 ipv6_prefix_count:
375 description: The number of IPv6 prefixes that Amazon Web Services automatically assigned to the network interface.
376 type: int
377 returned: if applicable
378 primary_ipv6:
379 description: The primary IPv6 address of the network interface.
380 type: str
381 returned: if applicable
382 ena_srd_specification:
383 description: Contains the ENA Express settings for instances launched from your launch template.
384 type: dict
385 returned: if applicable
386 contains:
387 ena_srd_enabled:
388 description: Indicates whether ENA Express is enabled for the network interface.
389 type: bool
390 returned: always
391 ena_srd_udp_specification:
392 description: Configures ENA Express for UDP network traffic.
393 type: dict
394 returned: always
395 contains:
396 ena_srd_udp_enabled:
397 description: Indicates whether UDP traffic to and from the instance uses ENA Express.
398 type: bool
399 returned: always
400 connection_tracking_specification:
401 description:
402 - A security group connection tracking specification that enables you to set the timeout
403 for connection tracking on an Elastic network interface.
404 type: dict
405 returned: if applicable
406 contains:
407 tcp_established_timeout:
408 description: Timeout (in seconds) for idle TCP connections in an established state.
409 type: int
410 returned: always
411 udp_timeout:
412 description:
413 - Timeout (in seconds) for idle UDP flows that have seen traffic only in a single direction
414 or a single request-response transaction.
415 type: int
416 returned: always
417 udp_stream_timeout:
418 description:
419 - Timeout (in seconds) for idle UDP flows classified as streams which have seen more
420 than one request-response transaction.
421 type: int
422 returned: always
423 ram_disk_id:
424 description: The ID of the RAM disk, if applicable.
425 type: str
426 returned: if applicable
427 disable_api_termination:
428 description: If set to true, indicates that the instance cannot be terminated using the Amazon EC2 console, command line tool, or API.
429 type: bool
430 returned: if applicable
431 instance_initiated_shutdown_behavior:
432 description: Indicates whether an instance stops or terminates when you initiate shutdown from the instance.
433 type: str
434 returned: if applicable
435 user_data:
436 description: The user data for the instance.
437 type: str
438 returned: if applicable
439 tag_specifications:
440 description: The tags that are applied to the resources that are created during instance launch.
441 type: list
442 elements: dict
443 returned: if applicable
444 contains:
445 resource_type:
446 description: The type of resource to tag.
447 type: str
448 returned: always
449 tags:
450 description: The tags for the resource.
451 type: list
452 elements: dict
453 contains:
454 key:
455 description: The key of the tag.
456 type: str
457 returned: always
458 value:
459 description: The value of the tag.
460 type: str
461 returned: always
462 enclave_options:
463 description: Indicates whether the instance is enabled for Amazon Web Services Nitro Enclaves.
464 type: dict
465 returned: if applicable
466 contains:
467 enabled:
468 description: If this parameter is set to true, the instance is enabled for Amazon Web Services Nitro Enclaves.
469 type: bool
470 returned: always
471 metadata_options:
472 description: The metadata options for the instance.
473 type: dict
474 returned: if applicable
475 contains:
476 state:
477 description: The state of the metadata option changes.
478 type: str
479 returned: if applicable
480 http_tokens:
481 description: Indicates whether IMDSv2 is required.
482 type: str
483 returned: if applicable
484 http_put_response_hop_limit:
485 description: The desired HTTP PUT response hop limit for instance metadata requests.
486 type: int
487 returned: if applicable
488 http_endpoint:
489 description: Enables or disables the HTTP metadata endpoint on your instances.
490 type: str
491 returned: if applicable
492 http_protocol_ipv6:
493 description: Enables or disables the IPv6 endpoint for the instance metadata service.
494 type: str
495 returned: if applicable
496 instance_metadata_tags:
497 description: Set to enabled to allow access to instance tags from the instance metadata.
498 type: str
499 returned: if applicable
500 cpu_options:
501 description: The CPU options for the instance.
502 type: dict
503 returned: if applicable
504 contains:
505 core_count:
506 description: The number of CPU cores for the instance.
507 type: int
508 returned: if applicable
509 threads_per_core:
510 description: The number of threads per CPU core.
511 type: int
512 returned: if applicable
513 amd_sev_snp:
514 description: Indicates whether the instance is enabled for AMD SEV-SNP.
515 type: int
516 returned: if applicable
517 security_group_ids:
518 description: The security group IDs.
519 type: list
520 elements: str
521 returned: if applicable
522 security_groups:
523 description: The security group names.
524 type: list
525 elements: str
526 returned: if applicable
527 """
528
529 from typing import Any
530 from typing import Dict
531 from typing import List
532
533 from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict
534
535 from ansible_collections.amazon.aws.plugins.module_utils.botocore import normalize_boto3_result
536 from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AnsibleEC2Error
537 from ansible_collections.amazon.aws.plugins.module_utils.ec2 import describe_launch_template_versions
538 from ansible_collections.amazon.aws.plugins.module_utils.ec2 import describe_launch_templates
539 from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
540 from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
541 from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
542
543
544 def list_launch_templates(client, module: AnsibleAWSModule) -> List[Dict[str, Any]]:
545 try:
546 # Describe launch templates
547 launch_templates = describe_launch_templates(
548 client,
549 launch_template_ids=module.params.get("launch_template_ids"),
550 filters=ansible_dict_to_boto3_filter_list(module.params.get("filters")),
551 )
552
553 # Describe launch templates versions
554 for template in launch_templates:
555 template["Versions"] = describe_launch_template_versions(
556 client, LaunchTemplateId=template["LaunchTemplateId"]
557 )
558
559 # format output
560 launch_templates = [camel_dict_to_snake_dict(t, ignore_list=["Tags"]) for t in launch_templates]
561 for t in launch_templates:
562 t["tags"] = boto3_tag_list_to_ansible_dict(t.pop("tags", {}))
563
564 return normalize_boto3_result(launch_templates)
565
566 except AnsibleEC2Error as e:
567 module.fail_json_aws_error(e)
568
569
570 def main():
571 argument_spec = dict(
572 launch_template_ids=dict(type="list", elements="str"),
573 filters=dict(default={}, type="dict"),
574 )
575
576 module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True)
577 client = module.client("ec2")
578
579 launch_templates = list_launch_templates(client, module)
580 module.exit_json(launch_templates=launch_templates)
581
582
583 if __name__ == "__main__":
584 main()