diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py index 929a2fef9a..14597a754d 100644 --- a/lib/ansible/runner/__init__.py +++ b/lib/ansible/runner/__init__.py @@ -663,7 +663,7 @@ class Runner(object): module_name = utils.template(self.module_name, inject, self.setup_cache) - tmp = self._get_tmp_path(conn) + tmp = self._make_tmp_path(conn) result = None if self.module_name == 'copy': @@ -717,21 +717,21 @@ class Runner(object): # ***************************************************** - def _get_tmp_path(self, conn): - ''' gets a temporary path on a remote box ''' + def _make_tmp_path(self, conn): + ''' make and return a temporary path on a remote box ''' - basetmp = C.DEFAULT_REMOTE_TMP + basefile = 'ansible-%s-%s' % (time.time(), random.randint(0, 2**48)) + basetmp = os.path.join(C.DEFAULT_REMOTE_TMP, basefile) if self.remote_user == 'root': - basetmp ="/var/tmp" - cmd = "mktemp -d %s/ansible.XXXXXX" % basetmp + basetmp = os.path.join('/var/tmp', basefile) + + cmd = 'mkdir -p %s' % basetmp if self.remote_user != 'root': - cmd = "mkdir -p %s && %s" % (basetmp, cmd) + cmd += ' && chmod a+x %s' % basetmp + cmd += ' && echo %s' % basetmp result = self._low_level_exec_command(conn, cmd, None, sudoable=False) cleaned = result.split("\n")[0].strip() + '/' - if self.remote_user != 'root': - cmd = 'chmod a+x %s' % cleaned - self._low_level_exec_command(conn, cmd, None, sudoable=False) return cleaned @@ -751,7 +751,7 @@ class Runner(object): else: raise errors.AnsibleFileNotFound("module %s not found in %s" % (module, self.module_path)) - out_path = tmp + module + out_path = os.path.join(tmp, module) # use the correct python interpreter for the host host_variables = self.inventory.get_variables(conn.host)