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:
parent
9cefd8f04f
commit
d8999800d1
1 changed files with 24 additions and 10 deletions
|
@ -430,24 +430,38 @@ class Runner(object):
|
|||
break
|
||||
if not found:
|
||||
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:
|
||||
inject.update(self.module_vars)
|
||||
|
||||
source = utils.template(source, inject, self.setup_cache)
|
||||
source = utils.path_dwim(self.basedir, source)
|
||||
|
||||
# transfer the file to a remote tmp location
|
||||
tmp_src = tmp + source.split('/')[-1]
|
||||
conn.put_file(utils.path_dwim(self.basedir, source), tmp_src)
|
||||
local_md5 = utils.local_md5(source)
|
||||
if local_md5 is None:
|
||||
result=dict(failed=True, msg="could not find src=%s" % source)
|
||||
return ReturnData(host=conn.host, result=result)
|
||||
|
||||
# install the copy module
|
||||
self.module_name = 'copy'
|
||||
module = self._transfer_module(conn, tmp, 'copy')
|
||||
remote_md5 = self._remote_md5(conn, tmp, dest)
|
||||
|
||||
# run the copy module
|
||||
args = "src=%s dest=%s" % (tmp_src, dest)
|
||||
exec_rc = self._execute_module(conn, tmp, module, args)
|
||||
exec_rc = None
|
||||
if local_md5 != remote_md5:
|
||||
# transfer the file to a remote tmp location
|
||||
tmp_src = tmp + source.split('/')[-1]
|
||||
conn.put_file(source, tmp_src)
|
||||
|
||||
# install the copy module
|
||||
self.module_name = 'copy'
|
||||
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():
|
||||
return self._chain_file_module(conn, tmp, exec_rc, options)
|
||||
|
|
Loading…
Reference in a new issue