From f74a1fa4f0b1a928a85c1316dfceb42637624a2f Mon Sep 17 00:00:00 2001 From: Seth Vidal Date: Tue, 16 Apr 2013 15:15:58 -0400 Subject: [PATCH] make atomic_replace use shutil.copy2 instead of os.rename() so it will work across filesystems --- lib/ansible/module_common.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/ansible/module_common.py b/lib/ansible/module_common.py index 8e221ad9e7..508fe93de1 100644 --- a/lib/ansible/module_common.py +++ b/lib/ansible/module_common.py @@ -797,7 +797,11 @@ class AnsibleModule(object): if self.selinux_enabled(): context = self.selinux_default_context(dest) self.set_context_if_different(src, context, False) - os.rename(src, dest) + try: + shutil.copy2(src, dest) + except shutil.Error, e: + self.fail_json(msg='Could not atomic_replace file: %s to %s: %s' % (src, dest, e)) + def run_command(self, args, check_rc=False, close_fds=False, executable=None, data=None): '''