From 038fd0d0f24475604deea3f2eb58303710a69a0c Mon Sep 17 00:00:00 2001 From: Sloane Hertel Date: Wed, 5 Sep 2018 12:50:03 -0400 Subject: [PATCH] elb_target_group - prevent a KeyError exception (#45169) Ensure ports to integers after allowing the key 'Targets' to be available in params --- changelogs/fragments/elb_target_group_fix_KeyError.yaml | 3 +++ lib/ansible/modules/cloud/amazon/elb_target_group.py | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/elb_target_group_fix_KeyError.yaml diff --git a/changelogs/fragments/elb_target_group_fix_KeyError.yaml b/changelogs/fragments/elb_target_group_fix_KeyError.yaml new file mode 100644 index 00000000000..120f0d45202 --- /dev/null +++ b/changelogs/fragments/elb_target_group_fix_KeyError.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: +- elb_target_group - cast target ports to integers before making API calls after the key 'Targets' is in params. diff --git a/lib/ansible/modules/cloud/amazon/elb_target_group.py b/lib/ansible/modules/cloud/amazon/elb_target_group.py index 7b42c6d2059..61796530dee 100644 --- a/lib/ansible/modules/cloud/amazon/elb_target_group.py +++ b/lib/ansible/modules/cloud/amazon/elb_target_group.py @@ -429,10 +429,6 @@ def create_or_update_target_group(connection, module): if params['TargetType'] == 'ip': fail_if_ip_target_type_not_supported(module) - # Correct type of target ports - for target in params['Targets']: - target['Port'] = int(target.get('Port', module.params.get('port'))) - # Get target group tg = get_target_group(connection, module) @@ -496,6 +492,10 @@ def create_or_update_target_group(connection, module): if module.params.get("targets"): params['Targets'] = module.params.get("targets") + # Correct type of target ports + for target in params['Targets']: + target['Port'] = int(target.get('Port', module.params.get('port'))) + # get list of current target instances. I can't see anything like a describe targets in the doco so # describe_target_health seems to be the only way to get them