From 482f0a8d1c3cf354fb12b9459340025ce27ca6db Mon Sep 17 00:00:00 2001 From: wimnat Date: Tue, 3 Nov 2015 01:03:31 +0000 Subject: [PATCH] Prevent ec2_remote_facts from failing when listing a terminated instance --- .../modules/extras/cloud/amazon/ec2_remote_facts.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/extras/cloud/amazon/ec2_remote_facts.py b/lib/ansible/modules/extras/cloud/amazon/ec2_remote_facts.py index cb92ccba74d..cf54fa0274d 100644 --- a/lib/ansible/modules/extras/cloud/amazon/ec2_remote_facts.py +++ b/lib/ansible/modules/extras/cloud/amazon/ec2_remote_facts.py @@ -76,6 +76,12 @@ def get_instance_info(instance): interfaces = [] for interface in instance.interfaces: interfaces.append({ 'id': interface.id, 'mac_address': interface.mac_address }.copy()) + + # If an instance is terminated, sourceDestCheck is no longer returned + try: + source_dest_check = instance.sourceDestCheck + except AttributeError: + source_dest_check = None instance_info = { 'id': instance.id, 'kernel': instance.kernel, @@ -90,7 +96,7 @@ def get_instance_info(instance): 'ramdisk': instance.ramdisk, 'tags': instance.tags, 'key_name': instance.key_name, - 'source_destination_check': instance.sourceDestCheck, + 'source_destination_check': source_dest_check, 'image_id': instance.image_id, 'groups': groups, 'interfaces': interfaces,