From 0e0b91534adcac5cd118a32689594e8e041be0e7 Mon Sep 17 00:00:00 2001 From: Will Thames Date: Wed, 28 Jun 2017 07:04:15 +1000 Subject: [PATCH] [cloud] Return target_group_names where sensible in ec2_asg_facts module (#26078) If target_group_arns is an empty list, then return an empty target_group_names list. If a connection to elbv2 is not obtainable, then it is not possible to return target_group_names --- lib/ansible/modules/cloud/amazon/ec2_asg_facts.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/ansible/modules/cloud/amazon/ec2_asg_facts.py b/lib/ansible/modules/cloud/amazon/ec2_asg_facts.py index 53cb6c75bf1..d1fdb9be577 100644 --- a/lib/ansible/modules/cloud/amazon/ec2_asg_facts.py +++ b/lib/ansible/modules/cloud/amazon/ec2_asg_facts.py @@ -375,10 +375,13 @@ def find_asgs(conn, module, name=None, tags=None): if 'target_group_ar_ns' in asg: asg['target_group_arns'] = asg['target_group_ar_ns'] del(asg['target_group_ar_ns']) - if elbv2 and asg.get('target_group_arns'): - 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']] + 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']] + else: + asg['target_group_names'] = [] matched_asgs.append(asg) return matched_asgs