Use a mktemp'd path for uploading modules

This commit is contained in:
Jeremy Katz 2012-02-23 21:01:02 -05:00
parent bd37864242
commit 25df80ff58

View file

@ -120,6 +120,7 @@ class Runner(object):
self._exec_command(conn, "chmod +x %s" % outpath) self._exec_command(conn, "chmod +x %s" % outpath)
cmd = self._command(outpath) cmd = self._command(outpath)
result = self._exec_command(conn, cmd) result = self._exec_command(conn, cmd)
self._exec_command(conn, "rm -f %s" % outpath)
conn.close() conn.close()
return [ host, True, json.loads(result) ] return [ host, True, json.loads(result) ]
else: else:
@ -142,15 +143,17 @@ class Runner(object):
results = "\n".join(stdout.readlines()) results = "\n".join(stdout.readlines())
return results 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): def _copy_module(self, conn):
''' transfer a module over SFTP ''' ''' transfer a module over SFTP '''
in_path = os.path.expanduser( in_path = os.path.expanduser(
os.path.join(self.module_path, self.module_name) os.path.join(self.module_path, self.module_name)
) )
out_path = os.path.join( out_path = self._get_tmp_path(conn, "ansible_%s" % self.module_name)
"/var/spool/",
"ansible_%s" % self.module_name
)
sftp = conn.open_sftp() sftp = conn.open_sftp()
sftp.put(in_path, out_path) sftp.put(in_path, out_path)
sftp.close() sftp.close()