Commit a1428d6b by Toshio Kuratomi

Remove tmp as a parameter to the connection plugins

There doesn't appear to be anything that actually uses tmp_path in the
connection plugins so we don't need to pass that in to exec_command.
That change also means that we don't need to pass tmp_path around in
many places in the action plugins any more.  there may be more cleanup
that can be done there as well (the action plugin's public run() method
takes tmp as a keyword arg but that may not be necessary).

As a sideeffect of this patch, some potential problems with chmod and
the patch, assemble, copy, and template modules has been fixed (those
modules called _remote_chmod() with the wrong order for their
parameters.  Removing the tmp parameter fixed them.)
parent 95b371dd
Subproject commit e8227dea7a28bc39bf15f3bb26b76f3f29d5b60d Subproject commit a580acc12a28b48b432607ad506f1d410db742ae
...@@ -177,7 +177,7 @@ class ActionBase: ...@@ -177,7 +177,7 @@ class ActionBase:
cmd = self._connection._shell.mkdtemp(basefile, use_system_tmp, tmp_mode) cmd = self._connection._shell.mkdtemp(basefile, use_system_tmp, tmp_mode)
self._display.debug("executing _low_level_execute_command to create the tmp path") self._display.debug("executing _low_level_execute_command to create the tmp path")
result = self._low_level_execute_command(cmd, None, sudoable=False) result = self._low_level_execute_command(cmd, sudoable=False)
self._display.debug("done with creation of tmp path") self._display.debug("done with creation of tmp path")
# error handling on this seems a little aggressive? # error handling on this seems a little aggressive?
...@@ -218,7 +218,7 @@ class ActionBase: ...@@ -218,7 +218,7 @@ class ActionBase:
# If we have gotten here we have a working ssh configuration. # If we have gotten here we have a working ssh configuration.
# If ssh breaks we could leave tmp directories out on the remote system. # If ssh breaks we could leave tmp directories out on the remote system.
self._display.debug("calling _low_level_execute_command to remove the tmp path") self._display.debug("calling _low_level_execute_command to remove the tmp path")
self._low_level_execute_command(cmd, None, sudoable=False) self._low_level_execute_command(cmd, sudoable=False)
self._display.debug("done removing the tmp path") self._display.debug("done removing the tmp path")
def _transfer_data(self, remote_path, data): def _transfer_data(self, remote_path, data):
...@@ -248,18 +248,18 @@ class ActionBase: ...@@ -248,18 +248,18 @@ class ActionBase:
return remote_path return remote_path
def _remote_chmod(self, tmp, mode, path, sudoable=False): def _remote_chmod(self, mode, path, sudoable=False):
''' '''
Issue a remote chmod command Issue a remote chmod command
''' '''
cmd = self._connection._shell.chmod(mode, path) cmd = self._connection._shell.chmod(mode, path)
self._display.debug("calling _low_level_execute_command to chmod the remote path") self._display.debug("calling _low_level_execute_command to chmod the remote path")
res = self._low_level_execute_command(cmd, tmp, sudoable=sudoable) res = self._low_level_execute_command(cmd, sudoable=sudoable)
self._display.debug("done with chmod call") self._display.debug("done with chmod call")
return res return res
def _remote_checksum(self, tmp, path, all_vars): def _remote_checksum(self, path, all_vars):
''' '''
Takes a remote checksum and returns 1 if no file Takes a remote checksum and returns 1 if no file
''' '''
...@@ -268,7 +268,7 @@ class ActionBase: ...@@ -268,7 +268,7 @@ class ActionBase:
cmd = self._connection._shell.checksum(path, python_interp) cmd = self._connection._shell.checksum(path, python_interp)
self._display.debug("calling _low_level_execute_command to get the remote checksum") self._display.debug("calling _low_level_execute_command to get the remote checksum")
data = self._low_level_execute_command(cmd, tmp, sudoable=True) data = self._low_level_execute_command(cmd, sudoable=True)
self._display.debug("done getting the remote checksum") self._display.debug("done getting the remote checksum")
# FIXME: implement this function? # FIXME: implement this function?
#data2 = utils.last_non_blank_line(data['stdout']) #data2 = utils.last_non_blank_line(data['stdout'])
...@@ -286,7 +286,7 @@ class ActionBase: ...@@ -286,7 +286,7 @@ class ActionBase:
# this will signal that it changed and allow things to keep going # this will signal that it changed and allow things to keep going
return "INVALIDCHECKSUM" return "INVALIDCHECKSUM"
def _remote_expand_user(self, path, tmp): def _remote_expand_user(self, path):
''' takes a remote path and performs tilde expansion on the remote host ''' ''' takes a remote path and performs tilde expansion on the remote host '''
if not path.startswith('~'): # FIXME: Windows paths may start with "~ instead of just ~ if not path.startswith('~'): # FIXME: Windows paths may start with "~ instead of just ~
return path return path
...@@ -300,7 +300,7 @@ class ActionBase: ...@@ -300,7 +300,7 @@ class ActionBase:
cmd = self._connection._shell.expand_user(expand_path) cmd = self._connection._shell.expand_user(expand_path)
self._display.debug("calling _low_level_execute_command to expand the remote user path") self._display.debug("calling _low_level_execute_command to expand the remote user path")
data = self._low_level_execute_command(cmd, tmp, sudoable=False) data = self._low_level_execute_command(cmd, sudoable=False)
self._display.debug("done expanding the remote user path") self._display.debug("done expanding the remote user path")
#initial_fragment = utils.last_non_blank_line(data['stdout']) #initial_fragment = utils.last_non_blank_line(data['stdout'])
initial_fragment = data['stdout'].strip().splitlines()[-1] initial_fragment = data['stdout'].strip().splitlines()[-1]
...@@ -377,7 +377,7 @@ class ActionBase: ...@@ -377,7 +377,7 @@ class ActionBase:
if tmp and "tmp" in tmp and self._play_context.become and self._play_context.become_user != 'root': if tmp and "tmp" in tmp and self._play_context.become and self._play_context.become_user != 'root':
# deal with possible umask issues once sudo'ed to other user # deal with possible umask issues once sudo'ed to other user
self._remote_chmod(tmp, 'a+r', remote_module_path) self._remote_chmod('a+r', remote_module_path)
cmd = "" cmd = ""
in_data = None in_data = None
...@@ -407,7 +407,7 @@ class ActionBase: ...@@ -407,7 +407,7 @@ class ActionBase:
sudoable = False sudoable = False
self._display.debug("calling _low_level_execute_command() for command %s" % cmd) self._display.debug("calling _low_level_execute_command() for command %s" % cmd)
res = self._low_level_execute_command(cmd, tmp, sudoable=sudoable, in_data=in_data) res = self._low_level_execute_command(cmd, sudoable=sudoable, in_data=in_data)
self._display.debug("_low_level_execute_command returned ok") self._display.debug("_low_level_execute_command returned ok")
if tmp and "tmp" in tmp and not C.DEFAULT_KEEP_REMOTE_FILES and not persist_files and delete_remote_tmp: if tmp and "tmp" in tmp and not C.DEFAULT_KEEP_REMOTE_FILES and not persist_files and delete_remote_tmp:
...@@ -415,7 +415,7 @@ class ActionBase: ...@@ -415,7 +415,7 @@ class ActionBase:
# not sudoing to root, so maybe can't delete files as that other user # not sudoing to root, so maybe can't delete files as that other user
# have to clean up temp files as original user in a second step # have to clean up temp files as original user in a second step
cmd2 = self._connection._shell.remove(tmp, recurse=True) cmd2 = self._connection._shell.remove(tmp, recurse=True)
self._low_level_execute_command(cmd2, tmp, sudoable=False) self._low_level_execute_command(cmd2, sudoable=False)
try: try:
data = json.loads(self._filter_leading_non_json_lines(res.get('stdout', ''))) data = json.loads(self._filter_leading_non_json_lines(res.get('stdout', '')))
...@@ -444,7 +444,7 @@ class ActionBase: ...@@ -444,7 +444,7 @@ class ActionBase:
self._display.debug("done with _execute_module (%s, %s)" % (module_name, module_args)) self._display.debug("done with _execute_module (%s, %s)" % (module_name, module_args))
return data return data
def _low_level_execute_command(self, cmd, tmp, sudoable=True, in_data=None, executable=None): def _low_level_execute_command(self, cmd, sudoable=True, in_data=None, executable=None):
''' '''
This is the function which executes the low level shell command, which This is the function which executes the low level shell command, which
may be commands to create/remove directories for temporary files, or to may be commands to create/remove directories for temporary files, or to
...@@ -467,7 +467,7 @@ class ActionBase: ...@@ -467,7 +467,7 @@ class ActionBase:
cmd = self._play_context.make_become_cmd(cmd, executable=executable) cmd = self._play_context.make_become_cmd(cmd, executable=executable)
self._display.debug("executing the command %s through the connection" % cmd) self._display.debug("executing the command %s through the connection" % cmd)
rc, stdout, stderr = self._connection.exec_command(cmd, tmp, in_data=in_data, sudoable=sudoable) rc, stdout, stderr = self._connection.exec_command(cmd, in_data=in_data, sudoable=sudoable)
self._display.debug("command execution done") self._display.debug("command execution done")
if not isinstance(stdout, string_types): if not isinstance(stdout, string_types):
...@@ -510,7 +510,7 @@ class ActionBase: ...@@ -510,7 +510,7 @@ class ActionBase:
return None return None
def _get_diff_data(self, tmp, destination, source, task_vars, source_file=True): def _get_diff_data(self, destination, source, task_vars, source_file=True):
diff = {} diff = {}
self._display.debug("Going to peek to see if file has changed permissions") self._display.debug("Going to peek to see if file has changed permissions")
......
...@@ -106,21 +106,21 @@ class ActionModule(ActionBase): ...@@ -106,21 +106,21 @@ class ActionModule(ActionBase):
path = self._assemble_from_fragments(src, delimiter, _re, ignore_hidden) path = self._assemble_from_fragments(src, delimiter, _re, ignore_hidden)
path_checksum = checksum_s(path) path_checksum = checksum_s(path)
dest = self._remote_expand_user(dest, tmp) dest = self._remote_expand_user(dest)
remote_checksum = self._remote_checksum(tmp, dest, all_vars=task_vars) remote_checksum = self._remote_checksum(dest, all_vars=task_vars)
diff = {} diff = {}
if path_checksum != remote_checksum: if path_checksum != remote_checksum:
resultant = file(path).read() resultant = file(path).read()
if self._play_context.diff: if self._play_context.diff:
diff = self._get_diff_data(tmp, dest, path, task_vars) diff = self._get_diff_data(dest, path, task_vars)
xfered = self._transfer_data('src', resultant) xfered = self._transfer_data('src', resultant)
# 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._play_context.become and self._play_context.become_user != 'root': if self._play_context.become and self._play_context.become_user != 'root':
self._remote_chmod('a+r', xfered, tmp) self._remote_chmod('a+r', xfered)
# run the copy module # run the copy module
......
...@@ -43,12 +43,12 @@ class ActionModule(ActionBase): ...@@ -43,12 +43,12 @@ class ActionModule(ActionBase):
# configure, upload, and chmod the target module # configure, upload, and chmod the target module
(module_style, shebang, module_data) = self._configure_module(module_name=module_name, module_args=self._task.args, task_vars=task_vars) (module_style, shebang, module_data) = self._configure_module(module_name=module_name, module_args=self._task.args, task_vars=task_vars)
self._transfer_data(remote_module_path, module_data) self._transfer_data(remote_module_path, module_data)
self._remote_chmod(tmp, 'a+rx', remote_module_path) self._remote_chmod('a+rx', remote_module_path)
# configure, upload, and chmod the async_wrapper module # configure, upload, and chmod the async_wrapper module
(async_module_style, shebang, async_module_data) = self._configure_module(module_name='async_wrapper', module_args=dict(), task_vars=task_vars) (async_module_style, shebang, async_module_data) = self._configure_module(module_name='async_wrapper', module_args=dict(), task_vars=task_vars)
self._transfer_data(async_module_path, async_module_data) self._transfer_data(async_module_path, async_module_data)
self._remote_chmod(tmp, 'a+rx', async_module_path) self._remote_chmod('a+rx', async_module_path)
argsfile = self._transfer_data(self._connection._shell.join_path(tmp, 'arguments'), json.dumps(self._task.args)) argsfile = self._transfer_data(self._connection._shell.join_path(tmp, 'arguments'), json.dumps(self._task.args))
...@@ -56,7 +56,7 @@ class ActionModule(ActionBase): ...@@ -56,7 +56,7 @@ class ActionModule(ActionBase):
async_jid = str(random.randint(0, 999999999999)) async_jid = str(random.randint(0, 999999999999))
async_cmd = " ".join([str(x) for x in [env_string, async_module_path, async_jid, async_limit, remote_module_path, argsfile]]) async_cmd = " ".join([str(x) for x in [env_string, async_module_path, async_jid, async_limit, remote_module_path, argsfile]])
result = self._low_level_execute_command(cmd=async_cmd, tmp=None) result = self._low_level_execute_command(cmd=async_cmd)
# clean up after # clean up after
if tmp and "tmp" in tmp and not C.DEFAULT_KEEP_REMOTE_FILES: if tmp and "tmp" in tmp and not C.DEFAULT_KEEP_REMOTE_FILES:
......
...@@ -132,7 +132,7 @@ class ActionModule(ActionBase): ...@@ -132,7 +132,7 @@ class ActionModule(ActionBase):
tmp = self._make_tmp_path() tmp = self._make_tmp_path()
# expand any user home dir specifier # expand any user home dir specifier
dest = self._remote_expand_user(dest, tmp) dest = self._remote_expand_user(dest)
diffs = [] diffs = []
for source_full, source_rel in source_files: for source_full, source_rel in source_files:
...@@ -153,7 +153,7 @@ class ActionModule(ActionBase): ...@@ -153,7 +153,7 @@ class ActionModule(ActionBase):
dest_file = self._connection._shell.join_path(dest) dest_file = self._connection._shell.join_path(dest)
# Attempt to get the remote checksum # Attempt to get the remote checksum
remote_checksum = self._remote_checksum(tmp, dest_file, all_vars=task_vars) remote_checksum = self._remote_checksum(dest_file, all_vars=task_vars)
if remote_checksum == '3': if remote_checksum == '3':
# The remote_checksum was executed on a directory. # The remote_checksum was executed on a directory.
...@@ -164,7 +164,7 @@ class ActionModule(ActionBase): ...@@ -164,7 +164,7 @@ class ActionModule(ActionBase):
else: else:
# Append the relative source location to the destination and retry remote_checksum # Append the relative source location to the destination and retry remote_checksum
dest_file = self._connection._shell.join_path(dest, source_rel) dest_file = self._connection._shell.join_path(dest, source_rel)
remote_checksum = self._remote_checksum(tmp, dest_file, all_vars=task_vars) remote_checksum = self._remote_checksum(dest_file, all_vars=task_vars)
if remote_checksum != '1' and not force: if remote_checksum != '1' and not force:
# remote_file does not exist so continue to next iteration. # remote_file does not exist so continue to next iteration.
...@@ -181,7 +181,7 @@ class ActionModule(ActionBase): ...@@ -181,7 +181,7 @@ class ActionModule(ActionBase):
tmp = self._make_tmp_path() tmp = self._make_tmp_path()
if self._play_context.diff and not raw: if self._play_context.diff and not raw:
diffs.append(self._get_diff_data(tmp, dest_file, source_full, task_vars)) diffs.append(self._get_diff_data(dest_file, source_full, task_vars))
if self._play_context.check_mode: if self._play_context.check_mode:
self._remove_tempfile_if_content_defined(content, content_tempfile) self._remove_tempfile_if_content_defined(content, content_tempfile)
...@@ -202,7 +202,7 @@ class ActionModule(ActionBase): ...@@ -202,7 +202,7 @@ class ActionModule(ActionBase):
# 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._play_context.become and self._play_context.become_user != 'root': if self._play_context.become and self._play_context.become_user != 'root':
self._remote_chmod('a+r', tmp_src, tmp) self._remote_chmod('a+r', tmp_src)
if raw: if raw:
# Continue to next iteration if raw is defined. # Continue to next iteration if raw is defined.
......
...@@ -52,10 +52,10 @@ class ActionModule(ActionBase): ...@@ -52,10 +52,10 @@ class ActionModule(ActionBase):
return dict(failed=True, msg="src and dest are required") return dict(failed=True, msg="src and dest are required")
source = self._connection._shell.join_path(source) source = self._connection._shell.join_path(source)
source = self._remote_expand_user(source, tmp) source = self._remote_expand_user(source)
# calculate checksum for the remote file # calculate checksum for the remote file
remote_checksum = self._remote_checksum(tmp, source, all_vars=task_vars) remote_checksum = self._remote_checksum(source, all_vars=task_vars)
# use slurp if sudo and permissions are lacking # use slurp if sudo and permissions are lacking
remote_data = None remote_data = None
......
...@@ -52,7 +52,7 @@ class ActionModule(ActionBase): ...@@ -52,7 +52,7 @@ class ActionModule(ActionBase):
if self._play_context.become and self._play_context.become_user != 'root': if self._play_context.become and self._play_context.become_user != 'root':
if not self._play_context.check_mode: if not self._play_context.check_mode:
self._remote_chmod('a+r', tmp_src, tmp) self._remote_chmod('a+r', tmp_src)
new_module_args = self._task.args.copy() new_module_args = self._task.args.copy()
new_module_args.update( new_module_args.update(
......
...@@ -31,7 +31,7 @@ class ActionModule(ActionBase): ...@@ -31,7 +31,7 @@ class ActionModule(ActionBase):
return dict(skipped=True) return dict(skipped=True)
executable = self._task.args.get('executable') executable = self._task.args.get('executable')
result = self._low_level_execute_command(self._task.args.get('_raw_params'), tmp=tmp, executable=executable) result = self._low_level_execute_command(self._task.args.get('_raw_params'), executable=executable)
# for some modules (script, raw), the sudo success key # for some modules (script, raw), the sudo success key
# may leak into the stdout due to the way the sudo/su # may leak into the stdout due to the way the sudo/su
......
...@@ -78,13 +78,13 @@ class ActionModule(ActionBase): ...@@ -78,13 +78,13 @@ class ActionModule(ActionBase):
sudoable = False sudoable = False
else: else:
chmod_mode = '+rx' chmod_mode = '+rx'
self._remote_chmod(tmp, chmod_mode, tmp_src, sudoable=sudoable) self._remote_chmod(chmod_mode, tmp_src, sudoable=sudoable)
# add preparation steps to one ssh roundtrip executing the script # add preparation steps to one ssh roundtrip executing the script
env_string = self._compute_environment_string() env_string = self._compute_environment_string()
script_cmd = ' '.join([env_string, tmp_src, args]) script_cmd = ' '.join([env_string, tmp_src, args])
result = self._low_level_execute_command(cmd=script_cmd, tmp=None, sudoable=True) result = self._low_level_execute_command(cmd=script_cmd, sudoable=True)
# clean up after # clean up after
if tmp and "tmp" in tmp and not C.DEFAULT_KEEP_REMOTE_FILES: if tmp and "tmp" in tmp and not C.DEFAULT_KEEP_REMOTE_FILES:
......
...@@ -31,8 +31,8 @@ class ActionModule(ActionBase): ...@@ -31,8 +31,8 @@ class ActionModule(ActionBase):
TRANSFERS_FILES = True TRANSFERS_FILES = True
def get_checksum(self, tmp, dest, all_vars, try_directory=False, source=None): def get_checksum(self, dest, all_vars, try_directory=False, source=None):
remote_checksum = self._remote_checksum(tmp, dest, all_vars=all_vars) remote_checksum = self._remote_checksum(dest, all_vars=all_vars)
if remote_checksum in ('0', '2', '3', '4'): if remote_checksum in ('0', '2', '3', '4'):
# Note: 1 means the file is not present which is fine; template # Note: 1 means the file is not present which is fine; template
...@@ -40,7 +40,7 @@ class ActionModule(ActionBase): ...@@ -40,7 +40,7 @@ class ActionModule(ActionBase):
if try_directory and remote_checksum == '3' and source: if try_directory and remote_checksum == '3' and source:
base = os.path.basename(source) base = os.path.basename(source)
dest = os.path.join(dest, base) dest = os.path.join(dest, base)
remote_checksum = self.get_checksum(tmp, dest, all_vars=all_vars, try_directory=False) remote_checksum = self.get_checksum(dest, all_vars=all_vars, try_directory=False)
if remote_checksum not in ('0', '2', '3', '4'): if remote_checksum not in ('0', '2', '3', '4'):
return remote_checksum return remote_checksum
...@@ -74,7 +74,7 @@ class ActionModule(ActionBase): ...@@ -74,7 +74,7 @@ class ActionModule(ActionBase):
source = self._loader.path_dwim_relative(self._loader.get_basedir(), 'templates', source) source = self._loader.path_dwim_relative(self._loader.get_basedir(), 'templates', source)
# Expand any user home dir specification # Expand any user home dir specification
dest = self._remote_expand_user(dest, tmp) dest = self._remote_expand_user(dest)
directory_prepended = False directory_prepended = False
if dest.endswith(os.sep): if dest.endswith(os.sep):
...@@ -128,7 +128,7 @@ class ActionModule(ActionBase): ...@@ -128,7 +128,7 @@ class ActionModule(ActionBase):
return dict(failed=True, msg=type(e).__name__ + ": " + str(e)) return dict(failed=True, msg=type(e).__name__ + ": " + str(e))
local_checksum = checksum_s(resultant) local_checksum = checksum_s(resultant)
remote_checksum = self.get_checksum(tmp, dest, task_vars, not directory_prepended, source=source) remote_checksum = self.get_checksum(dest, task_vars, not directory_prepended, source=source)
if isinstance(remote_checksum, dict): if isinstance(remote_checksum, dict):
# Error from remote_checksum is a dict. Valid return is a str # Error from remote_checksum is a dict. Valid return is a str
return remote_checksum return remote_checksum
...@@ -141,14 +141,14 @@ class ActionModule(ActionBase): ...@@ -141,14 +141,14 @@ class ActionModule(ActionBase):
# if showing diffs, we need to get the remote value # if showing diffs, we need to get the remote value
if self._play_context.diff: if self._play_context.diff:
diff = self._get_diff_data(tmp, dest, resultant, task_vars, source_file=False) diff = self._get_diff_data(dest, resultant, task_vars, source_file=False)
if not self._play_context.check_mode: # do actual work thorugh copy if not self._play_context.check_mode: # do actual work thorugh copy
xfered = self._transfer_data(self._connection._shell.join_path(tmp, 'source'), resultant) xfered = self._transfer_data(self._connection._shell.join_path(tmp, 'source'), resultant)
# 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._play_context.become and self._play_context.become_user != 'root': if self._play_context.become and self._play_context.become_user != 'root':
self._remote_chmod('a+r', xfered, tmp) self._remote_chmod('a+r', xfered)
# run the copy module # run the copy module
new_module_args.update( new_module_args.update(
......
...@@ -53,7 +53,7 @@ class ActionModule(ActionBase): ...@@ -53,7 +53,7 @@ class ActionModule(ActionBase):
if stat and stat.get('exists', False): if stat and stat.get('exists', False):
return dict(skipped=True, msg=("skipped, since %s exists" % creates)) return dict(skipped=True, msg=("skipped, since %s exists" % creates))
dest = self._remote_expand_user(dest, tmp) # CCTODO: Fix path for Windows hosts. dest = self._remote_expand_user(dest) # CCTODO: Fix path for Windows hosts.
source = os.path.expanduser(source) source = os.path.expanduser(source)
if copy: if copy:
...@@ -66,7 +66,7 @@ class ActionModule(ActionBase): ...@@ -66,7 +66,7 @@ class ActionModule(ActionBase):
else: else:
source = self._loader.path_dwim_relative(self._loader.get_basedir(), 'files', source) source = self._loader.path_dwim_relative(self._loader.get_basedir(), 'files', source)
remote_checksum = self._remote_checksum(tmp, dest, all_vars=task_vars) remote_checksum = self._remote_checksum(dest, all_vars=task_vars)
if remote_checksum != '3': if remote_checksum != '3':
return dict(failed=True, msg="dest '%s' must be an existing dir" % dest) return dict(failed=True, msg="dest '%s' must be an existing dir" % dest)
elif remote_checksum == '4': elif remote_checksum == '4':
...@@ -83,7 +83,7 @@ class ActionModule(ActionBase): ...@@ -83,7 +83,7 @@ class ActionModule(ActionBase):
if copy: if copy:
if self._play_context.become and self._play_context.become_user != 'root': if self._play_context.become and self._play_context.become_user != 'root':
if not self._play_context.check_mode: if not self._play_context.check_mode:
self._remote_chmod(tmp, 'a+r', tmp_src) self._remote_chmod('a+r', tmp_src)
# Build temporary module_args. # Build temporary module_args.
new_module_args = self._task.args.copy() new_module_args = self._task.args.copy()
......
...@@ -122,8 +122,17 @@ class ConnectionBase(with_metaclass(ABCMeta, object)): ...@@ -122,8 +122,17 @@ class ConnectionBase(with_metaclass(ABCMeta, object)):
@ensure_connect @ensure_connect
@abstractmethod @abstractmethod
def exec_command(self, cmd, tmp_path, in_data=None, executable=None, sudoable=True): def exec_command(self, cmd, in_data=None, sudoable=True):
"""Run a command on the remote host """Run a command on the remote host.
:arg cmd: byte string containing the command
:kwarg in_data: If set, this data is passed to the command's stdin.
This is used to implement pipelining. Currently not all
connection plugins implement pipelining.
:kwarg sudoable: Tell the connection plugin if we're executing
a command via a privilege escalation mechanism. This may affect
how the connection plugin returns data. Note that not all
connections can handle privilege escalation.
:returns: a tuple of (return code, stdout, stderr) The return code is :returns: a tuple of (return code, stdout, stderr) The return code is
an int while stdout and stderr are both byte strings. an int while stdout and stderr are both byte strings.
......
...@@ -236,7 +236,7 @@ class Connection(ConnectionBase): ...@@ -236,7 +236,7 @@ class Connection(ConnectionBase):
else: else:
return response.get('rc') == 0 return response.get('rc') == 0
def exec_command(self, cmd, tmp_path, become_user=None, sudoable=False, executable='/bin/sh', in_data=None): def exec_command(self, cmd, become_user=None, sudoable=False, executable='/bin/sh', in_data=None):
''' run a command on the remote host ''' ''' run a command on the remote host '''
if sudoable and self.runner.become and self.runner.become_method not in self.become_methods_supported: if sudoable and self.runner.become and self.runner.become_method not in self.become_methods_supported:
...@@ -256,7 +256,6 @@ class Connection(ConnectionBase): ...@@ -256,7 +256,6 @@ class Connection(ConnectionBase):
data = dict( data = dict(
mode='command', mode='command',
cmd=cmd, cmd=cmd,
tmp_path=tmp_path,
executable=executable, executable=executable,
) )
data = utils.jsonify(data) data = utils.jsonify(data)
......
...@@ -83,7 +83,7 @@ class Connection(ConnectionBase): ...@@ -83,7 +83,7 @@ class Connection(ConnectionBase):
local_cmd += cmd local_cmd += cmd
return local_cmd return local_cmd
def _buffered_exec_command(self, cmd, tmp_path, become_user=None, sudoable=False, executable='/bin/sh', in_data=None, stdin=subprocess.PIPE): def _buffered_exec_command(self, cmd, become_user=None, sudoable=False, executable='/bin/sh', in_data=None, stdin=subprocess.PIPE):
''' run a command on the chroot. This is only needed for implementing ''' run a command on the chroot. This is only needed for implementing
put_file() get_file() so that we don't have to read the whole file put_file() get_file() so that we don't have to read the whole file
into memory. into memory.
...@@ -110,10 +110,10 @@ class Connection(ConnectionBase): ...@@ -110,10 +110,10 @@ class Connection(ConnectionBase):
return p return p
def exec_command(self, cmd, tmp_path, become_user=None, sudoable=False, executable='/bin/sh', in_data=None): def exec_command(self, cmd, become_user=None, sudoable=False, executable='/bin/sh', in_data=None):
''' run a command on the chroot ''' ''' run a command on the chroot '''
p = self._buffered_exec_command(cmd, tmp_path, become_user, sudoable, executable, in_data) p = self._buffered_exec_command(cmd, become_user, sudoable, executable, in_data)
stdout, stderr = p.communicate() stdout, stderr = p.communicate()
return (p.returncode, stdout, stderr) return (p.returncode, stdout, stderr)
...@@ -126,7 +126,7 @@ class Connection(ConnectionBase): ...@@ -126,7 +126,7 @@ class Connection(ConnectionBase):
try: try:
with open(in_path, 'rb') as in_file: with open(in_path, 'rb') as in_file:
try: try:
p = self._buffered_exec_command('dd of=%s bs=%s' % (out_path, self.BUFSIZE), None, stdin=in_file) p = self._buffered_exec_command('dd of=%s bs=%s' % (out_path, self.BUFSIZE), stdin=in_file)
except OSError: except OSError:
raise AnsibleError("chroot connection requires dd command in the chroot") raise AnsibleError("chroot connection requires dd command in the chroot")
try: try:
...@@ -145,7 +145,7 @@ class Connection(ConnectionBase): ...@@ -145,7 +145,7 @@ class Connection(ConnectionBase):
self._display.vvv("FETCH %s TO %s" % (in_path, out_path), host=self.chroot) self._display.vvv("FETCH %s TO %s" % (in_path, out_path), host=self.chroot)
try: try:
p = self._buffered_exec_command('dd if=%s bs=%s' % (in_path, self.BUFSIZE), None) p = self._buffered_exec_command('dd if=%s bs=%s' % (in_path, self.BUFSIZE))
except OSError: except OSError:
raise AnsibleError("chroot connection requires dd command in the chroot") raise AnsibleError("chroot connection requires dd command in the chroot")
......
...@@ -88,9 +88,9 @@ class Connection(ConnectionBase): ...@@ -88,9 +88,9 @@ class Connection(ConnectionBase):
return self return self
def exec_command(self, cmd, tmp_path, in_data=None, sudoable=False): def exec_command(self, cmd, in_data=None, sudoable=False):
""" Run a command on the local host """ """ Run a command on the local host """
super(Connection, self).exec_command(cmd, tmp_path, in_data=in_data, sudoable=sudoable) super(Connection, self).exec_command(cmd, in_data=in_data, sudoable=sudoable)
# Don't currently support su # Don't currently support su
if in_data: if in_data:
......
...@@ -55,7 +55,7 @@ class Connection(object): ...@@ -55,7 +55,7 @@ class Connection(object):
self.client = fc.Client(self.host) self.client = fc.Client(self.host)
return self return self
def exec_command(self, cmd, tmp_path, become_user=None, sudoable=False, def exec_command(self, cmd, become_user=None, sudoable=False,
executable='/bin/sh', in_data=None): executable='/bin/sh', in_data=None):
''' run a command on the remote minion ''' ''' run a command on the remote minion '''
......
...@@ -101,7 +101,7 @@ class Connection(object): ...@@ -101,7 +101,7 @@ class Connection(object):
local_cmd += cmd local_cmd += cmd
return local_cmd return local_cmd
def _buffered_exec_command(self, cmd, tmp_path, become_user=None, sudoable=False, executable='/bin/sh', in_data=None, stdin=subprocess.PIPE): def _buffered_exec_command(self, cmd, become_user=None, sudoable=False, executable='/bin/sh', in_data=None, stdin=subprocess.PIPE):
''' run a command on the jail. This is only needed for implementing ''' run a command on the jail. This is only needed for implementing
put_file() get_file() so that we don't have to read the whole file put_file() get_file() so that we don't have to read the whole file
into memory. into memory.
...@@ -127,10 +127,10 @@ class Connection(object): ...@@ -127,10 +127,10 @@ class Connection(object):
return p return p
def exec_command(self, cmd, tmp_path, become_user=None, sudoable=False, executable='/bin/sh', in_data=None): def exec_command(self, cmd, become_user=None, sudoable=False, executable='/bin/sh', in_data=None):
''' run a command on the jail ''' ''' run a command on the jail '''
p = self._buffered_exec_command(cmd, tmp_path, become_user, sudoable, executable, in_data) p = self._buffered_exec_command(cmd, become_user, sudoable, executable, in_data)
stdout, stderr = p.communicate() stdout, stderr = p.communicate()
return (p.returncode, stdout, stderr) return (p.returncode, stdout, stderr)
......
...@@ -69,7 +69,7 @@ class Connection(object): ...@@ -69,7 +69,7 @@ class Connection(object):
local_cmd = '%s -q -c lxc:/// lxc-enter-namespace %s -- %s' % (self.cmd, self.lxc, cmd) local_cmd = '%s -q -c lxc:/// lxc-enter-namespace %s -- %s' % (self.cmd, self.lxc, cmd)
return local_cmd return local_cmd
def exec_command(self, cmd, tmp_path, become_user, sudoable=False, executable='/bin/sh', in_data=None): def exec_command(self, cmd, become_user, sudoable=False, executable='/bin/sh', in_data=None):
''' run a command on the chroot ''' ''' run a command on the chroot '''
if sudoable and self.runner.become and self.runner.become_method not in self.become_methods_supported: if sudoable and self.runner.become and self.runner.become_method not in self.become_methods_supported:
......
...@@ -46,10 +46,10 @@ class Connection(ConnectionBase): ...@@ -46,10 +46,10 @@ class Connection(ConnectionBase):
self._connected = True self._connected = True
return self return self
def exec_command(self, cmd, tmp_path, in_data=None, sudoable=True): def exec_command(self, cmd, in_data=None, sudoable=True):
''' run a command on the local host ''' ''' run a command on the local host '''
super(Connection, self).exec_command(cmd, tmp_path, in_data=in_data, sudoable=sudoable) super(Connection, self).exec_command(cmd, in_data=in_data, sudoable=sudoable)
self._display.debug("in local.exec_command()") self._display.debug("in local.exec_command()")
......
...@@ -189,10 +189,10 @@ class Connection(ConnectionBase): ...@@ -189,10 +189,10 @@ class Connection(ConnectionBase):
return ssh return ssh
def exec_command(self, cmd, tmp_path, in_data=None, sudoable=True): def exec_command(self, cmd, in_data=None, sudoable=True):
''' run a command on the remote host ''' ''' run a command on the remote host '''
super(Connection, self).exec_command(cmd, tmp_path, in_data=in_data, sudoable=sudoable) super(Connection, self).exec_command(cmd, in_data=in_data, sudoable=sudoable)
if in_data: if in_data:
raise AnsibleError("Internal Error: this module does not support optimized module pipelining") raise AnsibleError("Internal Error: this module does not support optimized module pipelining")
......
...@@ -285,10 +285,10 @@ class Connection(ConnectionBase): ...@@ -285,10 +285,10 @@ class Connection(ConnectionBase):
return return_tuple return return_tuple
def _exec_command(self, cmd, tmp_path, in_data=None, sudoable=True): def _exec_command(self, cmd, in_data=None, sudoable=True):
''' run a command on the remote host ''' ''' run a command on the remote host '''
super(Connection, self).exec_command(cmd, tmp_path, in_data=in_data, sudoable=sudoable) super(Connection, self).exec_command(cmd, in_data=in_data, sudoable=sudoable)
self._display.vvv("ESTABLISH SSH CONNECTION FOR USER: {0}".format(self._play_context.remote_user), host=self._play_context.remote_addr) self._display.vvv("ESTABLISH SSH CONNECTION FOR USER: {0}".format(self._play_context.remote_user), host=self._play_context.remote_addr)
......
...@@ -172,8 +172,8 @@ class Connection(ConnectionBase): ...@@ -172,8 +172,8 @@ class Connection(ConnectionBase):
self.protocol = self._winrm_connect() self.protocol = self._winrm_connect()
return self return self
def exec_command(self, cmd, tmp_path, in_data=None, sudoable=True): def exec_command(self, cmd, in_data=None, sudoable=True):
super(Connection, self).exec_command(cmd, tmp_path, in_data=in_data, sudoable=sudoable) super(Connection, self).exec_command(cmd, in_data=in_data, sudoable=sudoable)
cmd_parts = shlex.split(to_bytes(cmd), posix=False) cmd_parts = shlex.split(to_bytes(cmd), posix=False)
cmd_parts = map(to_unicode, cmd_parts) cmd_parts = map(to_unicode, cmd_parts)
script = None script = None
......
...@@ -110,7 +110,7 @@ class Connection(object): ...@@ -110,7 +110,7 @@ class Connection(object):
local_cmd += cmd local_cmd += cmd
return local_cmd return local_cmd
def _buffered_exec_command(self, cmd, tmp_path, become_user=None, sudoable=False, executable=None, in_data=None, stdin=subprocess.PIPE): def _buffered_exec_command(self, cmd, become_user=None, sudoable=False, executable=None, in_data=None, stdin=subprocess.PIPE):
''' run a command on the zone. This is only needed for implementing ''' run a command on the zone. This is only needed for implementing
put_file() get_file() so that we don't have to read the whole file put_file() get_file() so that we don't have to read the whole file
into memory. into memory.
...@@ -136,14 +136,14 @@ class Connection(object): ...@@ -136,14 +136,14 @@ class Connection(object):
return p return p
def exec_command(self, cmd, tmp_path, become_user=None, sudoable=False, executable=None, in_data=None): def exec_command(self, cmd, become_user=None, sudoable=False, executable=None, in_data=None):
''' run a command on the zone ''' ''' run a command on the zone '''
### TODO: Why all the precautions not to specify /bin/sh? (vs jail.py) ### TODO: Why all the precautions not to specify /bin/sh? (vs jail.py)
if executable == '/bin/sh': if executable == '/bin/sh':
executable = None executable = None
p = self._buffered_exec_command(cmd, tmp_path, become_user, sudoable, executable, in_data) p = self._buffered_exec_command(cmd, become_user, sudoable, executable, in_data)
stdout, stderr = p.communicate() stdout, stderr = p.communicate()
return (p.returncode, stdout, stderr) return (p.returncode, stdout, stderr)
......
...@@ -38,11 +38,11 @@ class TestActionBase(unittest.TestCase): ...@@ -38,11 +38,11 @@ class TestActionBase(unittest.TestCase):
play_context.become_user = play_context.remote_user = 'root' play_context.become_user = play_context.remote_user = 'root'
play_context.make_become_cmd = Mock(return_value='CMD') play_context.make_become_cmd = Mock(return_value='CMD')
action_base._low_level_execute_command('ECHO', '/tmp', sudoable=True) action_base._low_level_execute_command('ECHO', sudoable=True)
play_context.make_become_cmd.assert_not_called() play_context.make_become_cmd.assert_not_called()
play_context.remote_user = 'apo' play_context.remote_user = 'apo'
action_base._low_level_execute_command('ECHO', '/tmp', sudoable=True) action_base._low_level_execute_command('ECHO', sudoable=True)
play_context.make_become_cmd.assert_called_once_with('ECHO', executable=None) play_context.make_become_cmd.assert_called_once_with('ECHO', executable=None)
play_context.make_become_cmd.reset_mock() play_context.make_become_cmd.reset_mock()
...@@ -51,7 +51,7 @@ class TestActionBase(unittest.TestCase): ...@@ -51,7 +51,7 @@ class TestActionBase(unittest.TestCase):
C.BECOME_ALLOW_SAME_USER = True C.BECOME_ALLOW_SAME_USER = True
try: try:
play_context.remote_user = 'root' play_context.remote_user = 'root'
action_base._low_level_execute_command('ECHO SAME', '/tmp', sudoable=True) action_base._low_level_execute_command('ECHO SAME', sudoable=True)
play_context.make_become_cmd.assert_called_once_with('ECHO SAME', executable=None) play_context.make_become_cmd.assert_called_once_with('ECHO SAME', executable=None)
finally: finally:
C.BECOME_ALLOW_SAME_USER = become_allow_same_user C.BECOME_ALLOW_SAME_USER = become_allow_same_user
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment