Skip to content

Commit

Permalink
Gather information about ASG lifecycle hooks (ansible-collections#233)
Browse files Browse the repository at this point in the history
* Gather information about ASG lifecycle hooks for community.aws.ec2_asg_info
* add a changelog fragment to the change
* use fail_json_aws

Co-authored-by: Saleh Abbas <[email protected]>
Co-authored-by: Mark Chappell <[email protected]>
  • Loading branch information
3 people authored Mar 14, 2021
1 parent d24d8f1 commit 7c1b49f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/233-info-about-asg-lifecycle-hooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- ec2_asg_info - gather information about asg lifecycle hooks (https://github.com/ansible-collections/community.aws/pull/233).
47 changes: 47 additions & 0 deletions plugins/modules/ec2_asg_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,28 @@
returned: success
type: str
sample: "public-webapp-production-1"
lifecycle_hooks:
description: List of lifecycle hooks for the ASG.
returned: success
type: list
sample: [
{
"AutoScalingGroupName": "public-webapp-production-1",
"DefaultResult": "ABANDON",
"GlobalTimeout": 172800,
"HeartbeatTimeout": 3600,
"LifecycleHookName": "instance-launch",
"LifecycleTransition": "autoscaling:EC2_INSTANCE_LAUNCHING"
},
{
"AutoScalingGroupName": "public-webapp-production-1",
"DefaultResult": "ABANDON",
"GlobalTimeout": 172800,
"HeartbeatTimeout": 3600,
"LifecycleHookName": "instance-terminate",
"LifecycleTransition": "autoscaling:EC2_INSTANCE_TERMINATING"
}
]
load_balancer_names:
description: List of load balancers names attached to the ASG.
returned: success
Expand Down Expand Up @@ -289,6 +311,25 @@ def find_asgs(conn, module, name=None, tags=None):
],
"launch_config_name": "public-webapp-production-1",
"launch_configuration_name": "public-webapp-production-1",
"lifecycle_hooks":
[
{
"AutoScalingGroupName": "public-webapp-production-1",
"DefaultResult": "ABANDON",
"GlobalTimeout": 172800,
"HeartbeatTimeout": 3600,
"LifecycleHookName": "instance-launch",
"LifecycleTransition": "autoscaling:EC2_INSTANCE_LAUNCHING"
},
{
"AutoScalingGroupName": "public-webapp-production-1",
"DefaultResult": "ABANDON",
"GlobalTimeout": 172800,
"HeartbeatTimeout": 3600,
"LifecycleHookName": "instance-terminate",
"LifecycleTransition": "autoscaling:EC2_INSTANCE_TERMINATING"
}
],
"load_balancer_names": ["public-webapp-production-lb"],
"max_size": 4,
"min_size": 2,
Expand Down Expand Up @@ -381,6 +422,12 @@ def find_asgs(conn, module, name=None, tags=None):
module.fail_json_aws(e, msg="Failed to describe Target Groups")
else:
asg['target_group_names'] = []
# get asg lifecycle hooks if any
try:
asg_lifecyclehooks = conn.describe_lifecycle_hooks(AutoScalingGroupName=asg['auto_scaling_group_name'])
asg['lifecycle_hooks'] = asg_lifecyclehooks['LifecycleHooks']
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg="Failed to fetch information about ASG lifecycle hooks")
matched_asgs.append(asg)

return matched_asgs
Expand Down

0 comments on commit 7c1b49f

Please sign in to comment.