parent
391896ca9d
commit
a612137098
3 changed files with 22 additions and 20 deletions
|
@ -47,6 +47,20 @@ class ShellBase(AnsiblePlugin):
|
||||||
|
|
||||||
self.tempdir = None
|
self.tempdir = None
|
||||||
|
|
||||||
|
def _normalize_system_temps(self):
|
||||||
|
# Normalize the temp 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)
|
||||||
|
normalized_paths = [d.rstrip('/') for d in self.get_option('system_temps')]
|
||||||
|
|
||||||
|
# Make sure all system_temps are absolute otherwise they'd be relative to the login dir
|
||||||
|
# which is almost certainly going to fail in a cornercase.
|
||||||
|
if not all(os.path.isabs(d) for d in normalized_paths):
|
||||||
|
raise AnsibleError('The configured system_temps contains a relative path: {0}. All'
|
||||||
|
' system_temps must be absolute'.format(to_native(normalized_paths)))
|
||||||
|
|
||||||
|
self.set_option('system_temps', normalized_paths)
|
||||||
|
|
||||||
def set_options(self, task_keys=None, var_options=None, direct=None):
|
def set_options(self, task_keys=None, var_options=None, direct=None):
|
||||||
|
|
||||||
super(ShellBase, self).set_options(task_keys=task_keys, var_options=var_options, direct=direct)
|
super(ShellBase, self).set_options(task_keys=task_keys, var_options=var_options, direct=direct)
|
||||||
|
@ -54,18 +68,13 @@ class ShellBase(AnsiblePlugin):
|
||||||
# set env
|
# set env
|
||||||
self.env.update(self.get_option('environment'))
|
self.env.update(self.get_option('environment'))
|
||||||
|
|
||||||
# Normalize the temp directory strings. We don't use expanduser/expandvars because those
|
# We can remove the try: except in the future when we make ShellBase a proper subset of
|
||||||
# can vary between remote user and become user. Therefore the safest practice will be for
|
# *all* shells. Right now powershell and third party shells which do not use the
|
||||||
# this to always be specified as full paths)
|
# shell_common documentation fragment (and so do not have system_temps) will fail
|
||||||
normalized_system_temps = [d.rstrip('/') for d in self.get_option('system_temps')]
|
try:
|
||||||
|
self._normalize_system_temps()
|
||||||
# Make sure all system_temps are absolute otherwise they'd be relative to the login dir
|
except AnsibleError:
|
||||||
# which is almost certainly going to fail in a cornercase.
|
pass
|
||||||
if not all(os.path.isabs(d) for d in normalized_system_temps):
|
|
||||||
raise AnsibleError('The configured system_temps contains a relative path: {0}. All'
|
|
||||||
' system_temps must be absolute'.format(to_native(normalized_system_temps)))
|
|
||||||
|
|
||||||
self.set_option('system_temps', normalized_system_temps)
|
|
||||||
|
|
||||||
def env_prefix(self, **kwargs):
|
def env_prefix(self, **kwargs):
|
||||||
return ' '.join(['%s=%s' % (k, shlex_quote(text_type(v))) for k, v in kwargs.items()])
|
return ' '.join(['%s=%s' % (k, shlex_quote(text_type(v))) for k, v in kwargs.items()])
|
||||||
|
|
|
@ -1823,13 +1823,6 @@ class ShellModule(ShellBase):
|
||||||
|
|
||||||
# TODO: add binary module support
|
# TODO: add binary module support
|
||||||
|
|
||||||
def set_options(self, task_keys=None, var_options=None, direct=None):
|
|
||||||
|
|
||||||
super(ShellModule, self).set_options(task_keys=task_keys, var_options=var_options, direct=direct)
|
|
||||||
|
|
||||||
# set env
|
|
||||||
self.env.update(self.get_option('environment'))
|
|
||||||
|
|
||||||
def assert_safe_env_key(self, key):
|
def assert_safe_env_key(self, key):
|
||||||
if not self.safe_envkey.match(key):
|
if not self.safe_envkey.match(key):
|
||||||
raise AnsibleError("Invalid PowerShell environment key: %s" % key)
|
raise AnsibleError("Invalid PowerShell environment key: %s" % key)
|
||||||
|
|
|
@ -19,7 +19,7 @@ options:
|
||||||
- name: ansible_remote_tmp
|
- name: ansible_remote_tmp
|
||||||
system_temps:
|
system_temps:
|
||||||
description:
|
description:
|
||||||
- List of valid system temporary directories for Ansible to choose when it cannot use ``remote_temp``, normally due to permission issues.
|
- List of valid system temporary directories for Ansible to choose when it cannot use ``remote_temp``, normally due to permission issues. These must be world readable, writable, and executable.
|
||||||
default: [ /var/tmp, /tmp ]
|
default: [ /var/tmp, /tmp ]
|
||||||
type: list
|
type: list
|
||||||
env: [{name: ANSIBLE_SYSTEM_TMPS}]
|
env: [{name: ANSIBLE_SYSTEM_TMPS}]
|
||||||
|
|
Loading…
Reference in a new issue