summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Coca <bcoca@users.noreply.github.com>2017-01-25 13:09:36 -0500
committerBrian Coca <brian.coca+git@gmail.com>2017-01-25 13:19:51 -0500
commit89fdca092929fc39dbe864f6edd634f17f7d37a0 (patch)
tree6b21457260b0460caf0d3394e85cc4fedbe16c33
parent7164956cc638a59cb3209ead14240754f6497b3b (diff)
downloadansible-89fdca092929fc39dbe864f6edd634f17f7d37a0.tar.gz
make sure tmpdir resolvs user dirs (#20486)
* make sure tmpdir resolvs user dirs fixes #20332 supercedes #20484 * typo fix (cherry picked from commit 10fa2cd0efcc6bd6634f261da79e66c2d9be1dc0)
-rw-r--r--lib/ansible/plugins/action/__init__.py7
-rw-r--r--lib/ansible/plugins/shell/__init__.py8
2 files changed, 12 insertions, 3 deletions
diff --git a/lib/ansible/plugins/action/__init__.py b/lib/ansible/plugins/action/__init__.py
index 60795b60ee..4b4a677de1 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 44af0abb74..c6540d8f82 100644
--- a/lib/ansible/plugins/shell/__init__.py
+++ b/lib/ansible/plugins/shell/__init__.py
@@ -90,7 +90,7 @@ class ShellBase(object):
cmd = ['test', '-e', pipes.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))
@@ -106,13 +106,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)