From 87f8e37c2c11ff458c2b640f811725ed01c84345 Mon Sep 17 00:00:00 2001 From: Jason Witkowski Date: Mon, 8 Apr 2019 19:00:51 -0400 Subject: [PATCH] Fix for neither LaunchConfigName nor LaunchTemplate existing on object (#54692) --- .../fragments/54692-ec2_asg_fix_reading_properties.yml | 2 ++ lib/ansible/modules/cloud/amazon/ec2_asg.py | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/54692-ec2_asg_fix_reading_properties.yml diff --git a/changelogs/fragments/54692-ec2_asg_fix_reading_properties.yml b/changelogs/fragments/54692-ec2_asg_fix_reading_properties.yml new file mode 100644 index 00000000000..4041570e773 --- /dev/null +++ b/changelogs/fragments/54692-ec2_asg_fix_reading_properties.yml @@ -0,0 +1,2 @@ +bugfixes: + - ec2_asg - Fix error where ASG dict has no launch config or launch template key diff --git a/lib/ansible/modules/cloud/amazon/ec2_asg.py b/lib/ansible/modules/cloud/amazon/ec2_asg.py index d973ede1e1e..971fa4ea154 100644 --- a/lib/ansible/modules/cloud/amazon/ec2_asg.py +++ b/lib/ansible/modules/cloud/amazon/ec2_asg.py @@ -629,10 +629,13 @@ def get_properties(autoscaling_group): instance_facts[i['InstanceId']] = {'health_status': i['HealthStatus'], 'lifecycle_state': i['LifecycleState'], 'launch_config_name': i['LaunchConfigurationName']} - else: + elif i.get('LaunchTemplate'): instance_facts[i['InstanceId']] = {'health_status': i['HealthStatus'], 'lifecycle_state': i['LifecycleState'], 'launch_template': i['LaunchTemplate']} + else: + instance_facts[i['InstanceId']] = {'health_status': i['HealthStatus'], + 'lifecycle_state': i['LifecycleState']} if i['HealthStatus'] == 'Healthy' and i['LifecycleState'] == 'InService': properties['viable_instances'] += 1 if i['HealthStatus'] == 'Healthy':