fixed remote_src support, now actually copies and does not move

This commit is contained in:
Brian Coca 2015-11-12 09:39:37 -08:00
parent 0e0f87be12
commit 6e37f1dcef

View file

@ -19,7 +19,7 @@
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
import os
import time
import tempfile
DOCUMENTATION = '''
---
@ -214,7 +214,8 @@ def main():
backup = dict(default=False, type='bool'),
force = dict(default=True, aliases=['thirsty'], type='bool'),
validate = dict(required=False, type='str'),
directory_mode = dict(required=False)
directory_mode = dict(required=False),
remote_src = dict(required=False, type='bool'),
),
add_file_common_args=True,
supports_check_mode=True,
@ -228,6 +229,7 @@ def main():
validate = module.params.get('validate',None)
follow = module.params['follow']
mode = module.params['mode']
remote_src = module.params['remote_src']
if not os.path.exists(src):
module.fail_json(msg="Source %s failed to transfer" % (src))
@ -307,6 +309,11 @@ def main():
(rc,out,err) = module.run_command(validate % src)
if rc != 0:
module.fail_json(msg="failed to validate: rc:%s error:%s" % (rc,err))
if remote_src:
tmpdest = tempfile.mkstemp(dir=os.basedir(dest))
shutil.copy2(src, tmpdest)
module.atomic_move(tmpdest, dest)
else:
module.atomic_move(src, dest)
except IOError:
module.fail_json(msg="failed to copy: %s to %s" % (src, dest))