Debian Codegraph @

ansible_collections/community/aws/plugins/modules/autoscaling_complete_lifecycle_action.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: autoscaling_complete_lifecycle_action
10 short_description: Completes the lifecycle action of an instance
11 description:
12 - Used to complete the lifecycle action for the specified instance with the specified result.
13 version_added: "4.1.0"
14 author:
15 - Saleh Abbas (@salehabbas) <[email protected]>
16 options:
17 asg_name:
18 description:
19 - The name of the Auto Scaling Group which the instance belongs to.
20 type: str
21 required: true
22 lifecycle_hook_name:
23 description:
24 - The name of the lifecycle hook to complete.
25 type: str
26 required: true
27 lifecycle_action_result:
28 description:
29 - The action for the lifecycle hook to take.
30 choices: ['CONTINUE', 'ABANDON']
31 type: str
32 required: true
33 instance_id:
34 description:
35 - The ID of the instance.
36 type: str
37 required: true
38 extends_documentation_fragment:
39 - amazon.aws.common.modules
40 - amazon.aws.region.modules
41 - amazon.aws.boto3
42 """
43
44 EXAMPLES = r"""
45 # Note: These examples do not set authentication details, see the AWS Guide for details.
46 # Complete the lifecycle action
47 - aws_asg_complete_lifecycle_action:
48 asg_name: my-auto-scaling-group
49 lifecycle_hook_name: my-lifecycle-hook
50 lifecycle_action_result: CONTINUE
51 instance_id: i-123knm1l2312
52 """
53
54 RETURN = r"""
55 ---
56 status:
57 description: How things went
58 returned: success
59 type: str
60 sample: ["OK"]
61 """
62
63 try:
64 import botocore
65 except ImportError:
66 pass # caught by AnsibleAWSModule
67
68 from ansible_collections.community.aws.plugins.module_utils.modules import AnsibleCommunityAWSModule as AnsibleAWSModule
69
70
71 def main():
72 argument_spec = dict(
73 asg_name=dict(required=True, type="str"),
74 lifecycle_hook_name=dict(required=True, type="str"),
75 lifecycle_action_result=dict(required=True, type="str", choices=["CONTINUE", "ABANDON"]),
76 instance_id=dict(required=True, type="str"),
77 )
78
79 module = AnsibleAWSModule(argument_spec=argument_spec)
80
81 asg_name = module.params.get("asg_name")
82 lifecycle_hook_name = module.params.get("lifecycle_hook_name")
83 lifecycle_action_result = module.params.get("lifecycle_action_result")
84 instance_id = module.params.get("instance_id")
85
86 autoscaling = module.client("autoscaling")
87 try:
88 results = autoscaling.complete_lifecycle_action(
89 LifecycleHookName=lifecycle_hook_name,
90 AutoScalingGroupName=asg_name,
91 LifecycleActionResult=lifecycle_action_result,
92 InstanceId=instance_id,
93 )
94 except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
95 module.fail_json_aws(e, msg="Failed to completes the lifecycle action")
96
97 module.exit_json(results=results)
98
99
100 if __name__ == "__main__":
101 main()