Fix traceback in atomic_move (#18649)

Commit 8b08a28c89 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
This commit is contained in:
Adrian Likins 2016-11-28 15:19:42 -05:00 committed by GitHub
parent 6169d2d49f
commit dbbd2d79ff

View file

@ -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)