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':