diff --git a/lib/ansible/modules/cloud/amazon/ec2_asg.py b/lib/ansible/modules/cloud/amazon/ec2_asg.py index 83e663313b7..05a3fff742b 100644 --- a/lib/ansible/modules/cloud/amazon/ec2_asg.py +++ b/lib/ansible/modules/cloud/amazon/ec2_asg.py @@ -1497,7 +1497,7 @@ def get_instances_by_launch_config(props, lc_check, initial_instances): # Check if migrating from launch_template to launch_config first if 'launch_template' in props['instance_facts'][i]: old_instances.append(i) - elif props['instance_facts'][i]['launch_config_name'] == props['launch_config_name']: + elif props['instance_facts'][i].get('launch_config_name') == props['launch_config_name']: new_instances.append(i) else: old_instances.append(i) @@ -1524,7 +1524,7 @@ def get_instances_by_launch_template(props, lt_check, initial_instances): # Check if migrating from launch_config_name to launch_template_name first if 'launch_config_name' in props['instance_facts'][i]: old_instances.append(i) - elif props['instance_facts'][i]['launch_template'] == props['launch_template']: + elif props['instance_facts'][i].get('launch_template') == props['launch_template']: new_instances.append(i) else: old_instances.append(i)