From dbbd2d79ff4b3d49e5db1b4cd22f488c56ae009c Mon Sep 17 00:00:00 2001 From: Adrian Likins Date: Mon, 28 Nov 2016 15:19:42 -0500 Subject: [PATCH] Fix traceback in atomic_move (#18649) Commit 8b08a28c895666b9fc673e5bf26bd91b2be77fe6 removed a call to get_exception() that was needed. Without it, the fail_json references an undefined variable ('exception') and throws an exception. Add the get_exception() back in where needed and update references. Now the proper module failure is returned. Fixes #18628 --- lib/ansible/module_utils/basic.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py index 6eea60d825..8c89644c81 100644 --- a/lib/ansible/module_utils/basic.py +++ b/lib/ansible/module_utils/basic.py @@ -2086,12 +2086,14 @@ class AnsibleModule(object): try: os.rename(b_tmp_dest_name, b_dest) except (shutil.Error, OSError, IOError): + e = get_exception() if unsafe_writes: - self._unsafe_writes(b_tmp_dest_name, b_dest, get_exception()) + self._unsafe_writes(b_tmp_dest_name, b_dest, e) else: - self.fail_json(msg='Could not replace file: %s to %s: %s' % (src, dest, exception)) + self.fail_json(msg='Could not replace file: %s to %s: %s' % (src, dest, e)) except (shutil.Error, OSError, IOError): - self.fail_json(msg='Could not replace file: %s to %s: %s' % (src, dest, exception)) + e = get_exception() + self.fail_json(msg='Could not replace file: %s to %s: %s' % (src, dest, e)) finally: self.cleanup(b_tmp_dest_name)