mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 03:41:25 -07:00
Normalize usage of temp and tmp on tmp (#36221)
* Normalize usage of temp and tmp on tmp * Rename system_tmps system_tmpdirs * Add ANSIBLE_REMOTE_TMP spelling of environment variables
This commit is contained in:
parent
2678508d42
commit
06f73ad578
22 changed files with 99 additions and 92 deletions
|
@ -45,21 +45,21 @@ class ShellBase(AnsiblePlugin):
|
|||
'LC_ALL': module_locale,
|
||||
'LC_MESSAGES': module_locale}
|
||||
|
||||
self.tempdir = None
|
||||
self.tmpdir = None
|
||||
|
||||
def _normalize_system_temps(self):
|
||||
# Normalize the temp directory strings. We don't use expanduser/expandvars because those
|
||||
def _normalize_system_tmpdirs(self):
|
||||
# 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)
|
||||
normalized_paths = [d.rstrip('/') for d in self.get_option('system_temps')]
|
||||
normalized_paths = [d.rstrip('/') for d in self.get_option('system_tmpdirs')]
|
||||
|
||||
# Make sure all system_temps are absolute otherwise they'd be relative to the login dir
|
||||
# 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.
|
||||
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)))
|
||||
raise AnsibleError('The configured system_tmpdirs contains a relative path: {0}. All'
|
||||
' system_tmpdirs must be absolute'.format(to_native(normalized_paths)))
|
||||
|
||||
self.set_option('system_temps', normalized_paths)
|
||||
self.set_option('system_tmpdirs', normalized_paths)
|
||||
|
||||
def set_options(self, task_keys=None, var_options=None, direct=None):
|
||||
|
||||
|
@ -70,9 +70,9 @@ class ShellBase(AnsiblePlugin):
|
|||
|
||||
# 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_temps) will fail
|
||||
# shell_common documentation fragment (and so do not have system_tmpdirs) will fail
|
||||
try:
|
||||
self._normalize_system_temps()
|
||||
self._normalize_system_tmpdirs()
|
||||
except AnsibleError:
|
||||
pass
|
||||
|
||||
|
@ -128,10 +128,10 @@ class ShellBase(AnsiblePlugin):
|
|||
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 temp directory.
|
||||
# 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_temps' setting defines dirctories we can use for this purpose
|
||||
# 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.
|
||||
|
@ -139,13 +139,13 @@ class ShellBase(AnsiblePlugin):
|
|||
if system:
|
||||
tmpdir = tmpdir.rstrip('/')
|
||||
|
||||
if tmpdir in self.get_option('system_temps'):
|
||||
if tmpdir in self.get_option('system_tmpdirs'):
|
||||
basetmpdir = tmpdir
|
||||
else:
|
||||
basetmpdir = self.get_option('system_temps')[0]
|
||||
basetmpdir = self.get_option('system_tmpdirs')[0]
|
||||
else:
|
||||
if tmpdir is None:
|
||||
basetmpdir = self.get_option('remote_temp')
|
||||
basetmpdir = self.get_option('remote_tmp')
|
||||
else:
|
||||
basetmpdir = tmpdir
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue