From a260d99f74199814bd9a33b71c61cbe1bc8eb92c Mon Sep 17 00:00:00 2001
From: piotrkarbowski-ciklum <pika@ciklum.com>
Date: Wed, 2 Aug 2017 19:05:08 +0200
Subject: [PATCH] ec2_ami_copy.py: Fix WaiterError handling. (#27416)

* ec2_ami_copy.py: Fix WaiterError handling.

Change suggested by Adam Johnson at https://github.com/ansible/ansible/issues/26971

* ec2_ami_copy.py: WaiterError: fail_json: add exception parameter.

* ec2_ami_copy.py: import traceback
---
 lib/ansible/modules/cloud/amazon/ec2_ami_copy.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/ansible/modules/cloud/amazon/ec2_ami_copy.py b/lib/ansible/modules/cloud/amazon/ec2_ami_copy.py
index 86cc2e95547..c68738791b9 100644
--- a/lib/ansible/modules/cloud/amazon/ec2_ami_copy.py
+++ b/lib/ansible/modules/cloud/amazon/ec2_ami_copy.py
@@ -133,6 +133,8 @@ EXAMPLES = '''
 from ansible.module_utils.basic import AnsibleModule
 from ansible.module_utils.ec2 import (boto3_conn, ec2_argument_spec, get_aws_connection_info)
 
+import traceback
+
 try:
     import boto
     import boto.ec2
@@ -180,7 +182,7 @@ def copy_image(module, ec2):
 
         module.exit_json(changed=True, image_id=image_id)
     except WaiterError as we:
-        module.fail_json(msg='An error occurred waiting for the image to become available. (%s)' %  we.reason)
+        module.fail_json(msg='An error occurred waiting for the image to become available. (%s)' % str(we), exception=traceback.format_exc())
     except ClientError as ce:
         module.fail_json(msg=ce.message)
     except NoCredentialsError: