diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py index 2d91e810c2b..0ff87a1f0c9 100644 --- a/lib/ansible/module_utils/basic.py +++ b/lib/ansible/module_utils/basic.py @@ -2055,7 +2055,7 @@ class AnsibleModule(object): if e.errno not in [errno.EPERM, errno.EXDEV, errno.EACCES, errno.ETXTBSY, errno.EBUSY]: # only try workarounds for errno 18 (cross device), 1 (not permitted), 13 (permission denied) # and 26 (text file busy) which happens on vagrant synced folders and other 'exotic' non posix file systems - self.fail_json(msg='Could not replace file: %s to %s: %s' % (src, dest, e)) + self.fail_json(msg='Could not replace file: %s to %s: %s' % (src, dest, e), exception=traceback.format_exc()) else: b_dest_dir = os.path.dirname(b_dest) # Use bytes here. In the shippable CI, this fails with @@ -2075,7 +2075,7 @@ class AnsibleModule(object): # would end in something like: # file = _os.path.join(dir, pre + name + suf) # TypeError: can't concat bytes to str - self.fail_json(msg='Failed creating temp file for atomic move. This usually happens when using Python3 less than Python3.5. Please use Python2.x or Python3.5 or greater.', exception=sys.exc_info()) + self.fail_json(msg='Failed creating temp file for atomic move. This usually happens when using Python3 less than Python3.5. Please use Python2.x or Python3.5 or greater.', exception=traceback.format_exc()) b_tmp_dest_name = to_bytes(tmp_dest_name, errors='surrogate_or_strict') @@ -2108,10 +2108,10 @@ class AnsibleModule(object): if unsafe_writes and e.errno == errno.EBUSY: self._unsafe_writes(b_tmp_dest_name, b_dest) else: - self.fail_json(msg='Unable to rename file: %s to %s: %s' % (src, dest, e)) + self.fail_json(msg='Unable to rename file: %s to %s: %s' % (src, dest, e), exception=traceback.format_exc()) except (shutil.Error, OSError, IOError): e = get_exception() - self.fail_json(msg='Failed to replace file: %s to %s: %s' % (src, dest, e)) + self.fail_json(msg='Failed to replace file: %s to %s: %s' % (src, dest, e), exception=traceback.format_exc()) finally: self.cleanup(b_tmp_dest_name) @@ -2143,7 +2143,7 @@ class AnsibleModule(object): in_src.close() except (shutil.Error, OSError, IOError): e = get_exception() - self.fail_json(msg='Could not write data to file (%s) from (%s): %s' % (dest, src, e)) + self.fail_json(msg='Could not write data to file (%s) from (%s): %s' % (dest, src, e), exception=traceback.format_exc()) def _read_from_pipes(self, rpipes, rfds, file_descriptor):