From f0cf1b35d5d2f6235aa83e2fdd12f9b206a1847f Mon Sep 17 00:00:00 2001 From: Sloane Hertel Date: Thu, 21 Dec 2017 13:48:23 -0500 Subject: [PATCH] [ec2_asg_facts] Add exception handling to describing the target groups in case they are in the process of being deleted. (#33997) --- lib/ansible/modules/cloud/amazon/ec2_asg_facts.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/cloud/amazon/ec2_asg_facts.py b/lib/ansible/modules/cloud/amazon/ec2_asg_facts.py index 994a8453952..dd3c321e716 100644 --- a/lib/ansible/modules/cloud/amazon/ec2_asg_facts.py +++ b/lib/ansible/modules/cloud/amazon/ec2_asg_facts.py @@ -370,9 +370,13 @@ def find_asgs(conn, module, name=None, tags=None): del(asg['target_group_ar_ns']) if asg.get('target_group_arns'): if elbv2: - tg_paginator = elbv2.get_paginator('describe_target_groups') - tg_result = tg_paginator.paginate(TargetGroupArns=asg['target_group_arns']).build_full_result() - asg['target_group_names'] = [tg['TargetGroupName'] for tg in tg_result['TargetGroups']] + try: + tg_paginator = elbv2.get_paginator('describe_target_groups') + tg_result = tg_paginator.paginate(TargetGroupArns=asg['target_group_arns']).build_full_result() + asg['target_group_names'] = [tg['TargetGroupName'] for tg in tg_result['TargetGroups']] + except ClientError as e: + if e.response['Error']['Code'] == 'TargetGroupNotFound': + asg['target_group_names'] = [] else: asg['target_group_names'] = [] matched_asgs.append(asg)