1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Take a remote md5sum before a file transfer to decide whether to transfer the file or not.

Allows for efficient transfer of large files.  Templates do not sample first because they are small.
This commit is contained in:
Michael DeHaan 2012-07-07 09:10:18 -04:00
parent 6c08913448
commit c2b8fabf66

View file

@ -430,24 +430,38 @@ class Runner(object):
break break
if not found: if not found:
results=dict(failed=True, msg="could not find src in first_available_file list") results=dict(failed=True, msg="could not find src in first_available_file list")
return ReturnData(host=conn.host, is_error=True, results=results) return ReturnData(host=conn.host, results=results)
if self.module_vars is not None: if self.module_vars is not None:
inject.update(self.module_vars) inject.update(self.module_vars)
source = utils.template(source, inject, self.setup_cache) source = utils.template(source, inject, self.setup_cache)
source = utils.path_dwim(self.basedir, source)
# transfer the file to a remote tmp location local_md5 = utils.local_md5(source)
tmp_src = tmp + source.split('/')[-1] if local_md5 is None:
conn.put_file(utils.path_dwim(self.basedir, source), tmp_src) result=dict(failed=True, msg="could not find src=%s" % source)
return ReturnData(host=conn.host, result=result)
remote_md5 = self._remote_md5(conn, tmp, dest)
# install the copy module exec_rc = None
self.module_name = 'copy' if local_md5 != remote_md5:
module = self._transfer_module(conn, tmp, 'copy') # transfer the file to a remote tmp location
tmp_src = tmp + source.split('/')[-1]
conn.put_file(source, tmp_src)
# run the copy module # install the copy module
args = "src=%s dest=%s" % (tmp_src, dest) self.module_name = 'copy'
exec_rc = self._execute_module(conn, tmp, module, args) module = self._transfer_module(conn, tmp, 'copy')
# run the copy module
args = "src=%s dest=%s" % (tmp_src, dest)
exec_rc = self._execute_module(conn, tmp, module, args)
else:
# no need to transfer the file, already correct md5
result = dict(changed=False, md5sum=remote_md5, transferred=False)
exec_rc = ReturnData(host=conn.host, result=result)
if exec_rc.is_successful(): if exec_rc.is_successful():
return self._chain_file_module(conn, tmp, exec_rc, options) return self._chain_file_module(conn, tmp, exec_rc, options)