From 25df80ff58aae6ada66e5ca2e9fd21eb106dbe80 Mon Sep 17 00:00:00 2001 From: Jeremy Katz Date: Thu, 23 Feb 2012 21:01:02 -0500 Subject: [PATCH] Use a mktemp'd path for uploading modules --- lib/ansible/__init__.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/ansible/__init__.py b/lib/ansible/__init__.py index b57aee7aaa..374e7e9944 100755 --- a/lib/ansible/__init__.py +++ b/lib/ansible/__init__.py @@ -120,6 +120,7 @@ class Runner(object): self._exec_command(conn, "chmod +x %s" % outpath) cmd = self._command(outpath) result = self._exec_command(conn, cmd) + self._exec_command(conn, "rm -f %s" % outpath) conn.close() return [ host, True, json.loads(result) ] else: @@ -142,15 +143,17 @@ class Runner(object): results = "\n".join(stdout.readlines()) return results + def _get_tmp_path(self, conn, file_name): + output = self._exec_command(conn, "mktemp /tmp/%s.XXXXXX" % file_name) + return output.split("\n")[0] + def _copy_module(self, conn): ''' transfer a module over SFTP ''' in_path = os.path.expanduser( os.path.join(self.module_path, self.module_name) ) - out_path = os.path.join( - "/var/spool/", - "ansible_%s" % self.module_name - ) + out_path = self._get_tmp_path(conn, "ansible_%s" % self.module_name) + sftp = conn.open_sftp() sftp.put(in_path, out_path) sftp.close()