From bdeb370d7942119944ee4d04e94391fe6ffe2ff3 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Fri, 3 May 2013 21:58:27 -0400 Subject: [PATCH] fixed case in which move fails after remote user copies file and sudo to non root does the move Signed-off-by: Brian Coca --- lib/ansible/module_common.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/ansible/module_common.py b/lib/ansible/module_common.py index fec3a7f6d4..cbfb24af45 100644 --- a/lib/ansible/module_common.py +++ b/lib/ansible/module_common.py @@ -836,8 +836,11 @@ class AnsibleModule(object): except OSError, e: sys.stderr.write("could not cleanup %s: %s" % (tmp_dest, e)) - try: - shutil.move(src, tmp_dest) + try: # leaves tmp file behind when sudo and not root + if os.getenv("SUDO_USER") and os.getuid() != 0: + shutil.copy(src, tmp_dest) + else: + shutil.move(src, tmp_dest) if self.selinux_enabled(): self.set_context_if_different(tmp_dest, context, False) os.rename(tmp_dest, dest)