From 10fa2cd0efcc6bd6634f261da79e66c2d9be1dc0 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Wed, 25 Jan 2017 13:09:36 -0500 Subject: [PATCH] make sure tmpdir resolvs user dirs (#20486) * make sure tmpdir resolvs user dirs fixes #20332 supercedes #20484 * typo fix --- lib/ansible/plugins/action/__init__.py | 7 ++++++- lib/ansible/plugins/shell/__init__.py | 8 ++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/ansible/plugins/action/__init__.py b/lib/ansible/plugins/action/__init__.py index ac34b0fa40..b3a0213beb 100644 --- a/lib/ansible/plugins/action/__init__.py +++ b/lib/ansible/plugins/action/__init__.py @@ -218,7 +218,12 @@ class ActionBase(with_metaclass(ABCMeta, object)): tmp_mode = 0o700 - cmd = self._connection._shell.mkdtemp(basefile, use_system_tmp, tmp_mode) + if use_system_tmp: + tmpdir = None + else: + tmpdir = self._remote_expand_user(C.DEFAULT_REMOTE_TMP) + + cmd = self._connection._shell.mkdtemp(basefile, use_system_tmp, tmp_mode, tmpdir) result = self._low_level_execute_command(cmd, sudoable=False) # error handling on this seems a little aggressive? diff --git a/lib/ansible/plugins/shell/__init__.py b/lib/ansible/plugins/shell/__init__.py index 1a88009e9e..7b774a1848 100644 --- a/lib/ansible/plugins/shell/__init__.py +++ b/lib/ansible/plugins/shell/__init__.py @@ -91,7 +91,7 @@ class ShellBase(object): cmd = ['test', '-e', shlex_quote(path)] return ' '.join(cmd) - def mkdtemp(self, basefile=None, system=False, mode=None): + def mkdtemp(self, basefile=None, system=False, mode=None, tmpdir=None): if not basefile: basefile = 'ansible-tmp-%s-%s' % (time.time(), random.randint(0, 2**48)) @@ -107,13 +107,17 @@ class ShellBase(object): # to somewhere in or below /var/tmp and if so use /var/tmp. If # anything else we use /tmp (because /tmp is specified by POSIX nad # /var/tmp is not). + if system: if C.DEFAULT_REMOTE_TMP.startswith('/var/tmp'): basetmpdir = '/var/tmp' else: basetmpdir = '/tmp' - else: + elif tmpdir is None: basetmpdir = C.DEFAULT_REMOTE_TMP + else: + basetmpdir = tmpdir + basetmp = self.join_path(basetmpdir, basefile) cmd = 'mkdir -p %s echo %s %s' % (self._SHELL_SUB_LEFT, basetmp, self._SHELL_SUB_RIGHT)