Coverage for lib/ansible/plugins/shell/__init__.py : 68%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# (c) 2016 RedHat # # This file is part of Ansible. # # Ansible is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ansible is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
module_locale = C.DEFAULT_MODULE_LANG self.env = {'LANG': module_locale, 'LC_ALL': module_locale, 'LC_MESSAGES': module_locale}
# Normalize the tmp directory strings. We don't use expanduser/expandvars because those # can vary between remote user and become user. Therefore the safest practice will be for # this to always be specified as full paths)
# Make sure all system_tmpdirs are absolute otherwise they'd be relative to the login dir # which is almost certainly going to fail in a cornercase. raise AnsibleError('The configured system_tmpdirs contains a relative path: {0}. All' ' system_tmpdirs must be absolute'.format(to_native(normalized_paths)))
# set env
# We can remove the try: except in the future when we make ShellBase a proper subset of # *all* shells. Right now powershell and third party shells which do not use the # shell_common documentation fragment (and so do not have system_tmpdirs) will fail except AnsibleError: pass
# some shells (eg, powershell) are snooty about filenames/extensions, this lets the shell plugin have a say
return path.endswith('/')
cmd = ['chown', user] cmd.extend(paths) cmd = [shlex_quote(c) for c in cmd]
return ' '.join(cmd)
"""Only sets acls for users as that's really all we need""" cmd = ['setfacl', '-m', 'u:%s:%s' % (user, mode)] cmd.extend(paths) cmd = [shlex_quote(c) for c in cmd]
return ' '.join(cmd)
cmd = ['test', '-e', shlex_quote(path)] return ' '.join(cmd)
basefile = 'ansible-tmp-%s-%s' % (time.time(), random.randint(0, 2**48))
# When system is specified we have to create this in a directory where # other users can read and access the tmp directory. # This is because we use system to create tmp dirs for unprivileged users who are # sudo'ing to a second unprivileged user. # The 'system_tmpdirs' setting defines dirctories we can use for this purpose # the default are, /tmp and /var/tmp. # So we only allow one of those locations if system=True, using the # passed in tmpdir if it is valid or the first one from the setting if not.
tmpdir = tmpdir.rstrip('/')
if tmpdir in self.get_option('system_tmpdirs'): basetmpdir = tmpdir else: basetmpdir = self.get_option('system_tmpdirs')[0] else: basetmpdir = self.get_option('remote_tmp') else:
# change the umask in a subshell to achieve the desired mode # also for directories created with `mkdir -p`
''' Return a command to expand tildes in a path
It can be either "~" or "~username". We just ignore $HOME We use the POSIX definition of a username: http://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap03.html#tag_03_426 http://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap03.html#tag_03_276
Falls back to 'current workind directory' as we assume 'home is where the remote user ends up' '''
# Check that the user_path to expand is safe if not _USER_HOME_PATH_RE.match(user_home_path): # shlex_quote will make the shell return the string verbatim user_home_path = shlex_quote(user_home_path) # if present the user name is appended to resolve "that user's home" user_home_path += username
"""Return the working directory after connecting""" return 'echo %spwd%s' % (self._SHELL_SUB_LEFT, self._SHELL_SUB_RIGHT)
# don't quote the cmd if it's an empty string, because this will break pipelining mode
else: shebang = "" cmd_parts.append(arg_path)
"""Append an additional command if supported by the shell"""
"""wrap script execution with any necessary decoration (eg '&' for quoted powershell script paths)""" return cmd |