Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: Contributors to the Ansible project
5 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 from __future__ import annotations
8
9 DOCUMENTATION = r"""
10 ---
11 module: autoscaling_instance_info
12 version_added: 9.0.0
13 short_description: describe instances associated with AWS AutoScaling Groups (ASGs)
14 description:
15 - Describe instances associated with AWS AutoScaling Groups (ASGs).
16 author:
17 - "Mark Chappell (@tremble)"
18 options:
19 group_name:
20 description:
21 - Name of the AutoScaling Group to manage.
22 - O(group_name) and O(instance_ids) are mutually exclusive.
23 type: str
24 instance_ids:
25 description:
26 - The IDs of the EC2 instances.
27 - O(group_name) and O(instance_ids) are mutually exclusive.
28 type: list
29 elements: str
30 extends_documentation_fragment:
31 - amazon.aws.common.modules
32 - amazon.aws.region.modules
33 - amazon.aws.boto3
34 """
35
36 EXAMPLES = r"""
37 - name: Describe all instances in a region
38 amazon.aws.autoscaling_instance_info:
39 register: instances
40
41 - name: Describe a specific instance
42 amazon.aws.autoscaling_instance_info:
43 instance_ids:
44 - "i-123456789abcdef01"
45 register: instances
46
47 - name: Describe the instances attached to a specific Auto Scaling Group
48 amazon.aws.autoscaling_instance_info:
49 group_name: example-asg
50 register: instances
51 """
52
53 RETURN = r"""
54 auto_scaling_instances:
55 description: A description of the EC2 instances attached to an Auto Scaling group.
56 returned: always
57 type: list
58 contains:
59 availability_zone:
60 description: The availability zone that the instance is in.
61 returned: always
62 type: str
63 sample: "us-east-1a"
64 health_status:
65 description: The last reported health status of the instance.
66 returned: always
67 type: str
68 sample: "Healthy"
69 instance_id:
70 description: The ID of the instance.
71 returned: always
72 type: str
73 sample: "i-123456789abcdef01"
74 instance_type:
75 description: The instance type of the instance.
76 returned: always
77 type: str
78 sample: "t3.micro"
79 launch_configuration_name:
80 description: The name of the launch configuration used when launching the instance.
81 returned: When the instance was launched using an Auto Scaling launch configuration.
82 type: str
83 sample: "ansible-test-49630214-mchappel-thinkpadt14gen3-asg-instance-1"
84 launch_template:
85 description: A description of the launch template used when launching the instance.
86 returned: When the instance was launched using an Auto Scaling launch template.
87 type: dict
88 contains:
89 launch_template_id:
90 description: The ID of the launch template used when launching the instance.
91 returned: always
92 type: str
93 sample: "12345678-abcd-ef12-2345-6789abcdef01"
94 launch_template_name:
95 description: The name of the launch template used when launching the instance.
96 returned: always
97 type: str
98 sample: "example-launch-configuration"
99 version:
100 description: The version of the launch template used when launching the instance.
101 returned: always
102 type: str
103 sample: "$Default"
104 lifecycle_state:
105 description: The lifecycle state of the instance.
106 returned: always
107 type: str
108 sample: "InService"
109 protected_from_scale_in:
110 description: Whether the instance is protected from termination when the Auto Scaling group is scaled in.
111 returned: always
112 type: bool
113 sample: false
114 """
115
116 from ansible_collections.amazon.aws.plugins.module_utils.autoscaling import get_autoscaling_instances
117 from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
118 from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
119
120
121 def main():
122 argument_spec = dict(
123 group_name=dict(type="str"),
124 instance_ids=dict(type="list", elements="str"),
125 )
126
127 module = AnsibleAWSModule(
128 argument_spec=argument_spec,
129 supports_check_mode=True,
130 mutually_exclusive=[["instance_ids", "group_name"]],
131 )
132
133 client = module.client("autoscaling", retry_decorator=AWSRetry.jittered_backoff())
134
135 instances = get_autoscaling_instances(
136 client,
137 instance_ids=module.params["instance_ids"],
138 group_name=module.params["group_name"],
139 )
140
141 module.exit_json(changed=False, auto_scaling_instances=instances)
142
143
144 if __name__ == "__main__":
145 main()