mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-28 07:31:23 -07:00
Add raw copy support (raw=yes), tweak tempfile error message string.
This commit is contained in:
parent
2e38d92262
commit
c07dd07767
2 changed files with 31 additions and 7 deletions
|
@ -728,12 +728,15 @@ class Runner(object):
|
||||||
cmd += ' && echo %s' % basetmp
|
cmd += ' && echo %s' % basetmp
|
||||||
|
|
||||||
result = self._low_level_exec_command(conn, cmd, None, sudoable=False)
|
result = self._low_level_exec_command(conn, cmd, None, sudoable=False)
|
||||||
|
|
||||||
|
# error handling on this seems a little aggressive?
|
||||||
if result['rc'] != 0:
|
if result['rc'] != 0:
|
||||||
raise errors.AnsibleError('could not create temporary directory, SSH exited with result %d' % result['rc'])
|
raise errors.AnsibleError('could not create temporary directory, SSH (%s) exited with result %d' % (cmd, result['rc']))
|
||||||
|
|
||||||
rc = utils.last_non_blank_line(result['stdout']).strip() + '/'
|
rc = utils.last_non_blank_line(result['stdout']).strip() + '/'
|
||||||
# Catch any other failure conditions here; files should never be
|
# Catch failure conditions, files should never be
|
||||||
# written directly to /.
|
# written to locations in /.
|
||||||
if rc == '/':
|
if rc.startswith('/'):
|
||||||
raise errors.AnsibleError('failed to resolve remote temporary directory from %s: `%s` returned empty string' % (basetmp, cmd))
|
raise errors.AnsibleError('failed to resolve remote temporary directory from %s: `%s` returned empty string' % (basetmp, cmd))
|
||||||
return rc
|
return rc
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@ class ActionModule(object):
|
||||||
source = options.get('src', None)
|
source = options.get('src', None)
|
||||||
content = options.get('content', None)
|
content = options.get('content', None)
|
||||||
dest = options.get('dest', None)
|
dest = options.get('dest', None)
|
||||||
|
raw = utils.boolean(options.get('raw', 'no'))
|
||||||
force = utils.boolean(options.get('force', 'yes'))
|
force = utils.boolean(options.get('force', 'yes'))
|
||||||
|
|
||||||
if (source is None and content is None and not 'first_available_file' in inject) or dest is None:
|
if (source is None and content is None and not 'first_available_file' in inject) or dest is None:
|
||||||
|
@ -113,7 +114,7 @@ class ActionModule(object):
|
||||||
exec_rc = None
|
exec_rc = None
|
||||||
if local_md5 != remote_md5:
|
if local_md5 != remote_md5:
|
||||||
|
|
||||||
if self.runner.diff:
|
if self.runner.diff and not raw:
|
||||||
diff = self._get_diff_data(conn, tmp, inject, dest, source)
|
diff = self._get_diff_data(conn, tmp, inject, dest, source)
|
||||||
else:
|
else:
|
||||||
diff = {}
|
diff = {}
|
||||||
|
@ -123,16 +124,29 @@ class ActionModule(object):
|
||||||
os.remove(tmp_content)
|
os.remove(tmp_content)
|
||||||
return ReturnData(conn=conn, result=dict(changed=True), diff=diff)
|
return ReturnData(conn=conn, result=dict(changed=True), diff=diff)
|
||||||
|
|
||||||
|
|
||||||
# transfer the file to a remote tmp location
|
# transfer the file to a remote tmp location
|
||||||
tmp_src = tmp + 'source'
|
tmp_src = tmp + 'source'
|
||||||
conn.put_file(source, tmp_src)
|
|
||||||
|
if not raw:
|
||||||
|
conn.put_file(source, tmp_src)
|
||||||
|
else:
|
||||||
|
conn.put_file(source, dest)
|
||||||
|
|
||||||
if content is not None:
|
if content is not None:
|
||||||
os.remove(tmp_content)
|
os.remove(tmp_content)
|
||||||
|
|
||||||
# fix file permissions when the copy is done as a different user
|
# fix file permissions when the copy is done as a different user
|
||||||
if self.runner.sudo and self.runner.sudo_user != 'root':
|
if self.runner.sudo and self.runner.sudo_user != 'root' and not raw:
|
||||||
self.runner._low_level_exec_command(conn, "chmod a+r %s" % tmp_src, tmp)
|
self.runner._low_level_exec_command(conn, "chmod a+r %s" % tmp_src, tmp)
|
||||||
|
|
||||||
|
if raw:
|
||||||
|
return ReturnData(conn=conn, result=dict(dest=dest, changed=True))
|
||||||
|
|
||||||
# run the copy module
|
# run the copy module
|
||||||
|
if 'raw' in module_args:
|
||||||
|
# don't send down raw=no
|
||||||
|
module_args.pop('raw')
|
||||||
module_args = "%s src=%s original_basename=%s" % (module_args, pipes.quote(tmp_src), pipes.quote(os.path.basename(source)))
|
module_args = "%s src=%s original_basename=%s" % (module_args, pipes.quote(tmp_src), pipes.quote(os.path.basename(source)))
|
||||||
return self.runner._execute_module(conn, tmp, 'copy', module_args, inject=inject, complex_args=complex_args)
|
return self.runner._execute_module(conn, tmp, 'copy', module_args, inject=inject, complex_args=complex_args)
|
||||||
|
|
||||||
|
@ -142,7 +156,14 @@ class ActionModule(object):
|
||||||
|
|
||||||
if content is not None:
|
if content is not None:
|
||||||
os.remove(tmp_content)
|
os.remove(tmp_content)
|
||||||
|
|
||||||
|
if raw:
|
||||||
|
return ReturnData(conn=conn, result=dict(dest=dest, changed=False))
|
||||||
|
|
||||||
tmp_src = tmp + os.path.basename(source)
|
tmp_src = tmp + os.path.basename(source)
|
||||||
|
if 'raw' in module_args:
|
||||||
|
# don't send down raw=no
|
||||||
|
module_args.pop('raw')
|
||||||
module_args = "%s src=%s" % (module_args, pipes.quote(tmp_src))
|
module_args = "%s src=%s" % (module_args, pipes.quote(tmp_src))
|
||||||
if self.runner.check:
|
if self.runner.check:
|
||||||
module_args = "%s CHECKMODE=True" % module_args
|
module_args = "%s CHECKMODE=True" % module_args
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue