From 4c83c274e03b6d92238306c63ee1ed000af70418 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Thu, 25 Oct 2012 21:49:28 -0400 Subject: [PATCH] Don't close paramiko SFTP multiple times in the same runner pass. Noticeable performance increase. --- .../runner/connection_plugins/paramiko_ssh.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/ansible/runner/connection_plugins/paramiko_ssh.py b/lib/ansible/runner/connection_plugins/paramiko_ssh.py index e20e507a577..d3ed85f7e51 100644 --- a/lib/ansible/runner/connection_plugins/paramiko_ssh.py +++ b/lib/ansible/runner/connection_plugins/paramiko_ssh.py @@ -135,29 +135,29 @@ class Connection(object): if not os.path.exists(in_path): raise errors.AnsibleFileNotFound("file or module does not exist: %s" % in_path) try: - sftp = self.ssh.open_sftp() + self.sftp = self.ssh.open_sftp() except: raise errors.AnsibleError("failed to open a SFTP connection") try: - sftp.put(in_path, out_path) + self.sftp.put(in_path, out_path) except IOError: raise errors.AnsibleError("failed to transfer file to %s" % out_path) - sftp.close() def fetch_file(self, in_path, out_path): ''' save a remote file to the specified path ''' vvv("FETCH %s TO %s" % (in_path, out_path), host=self.host) try: - sftp = self.ssh.open_sftp() + self.sftp = self.ssh.open_sftp() except: raise errors.AnsibleError("failed to open a SFTP connection") try: - sftp.get(in_path, out_path) + self.sftp.get(in_path, out_path) except IOError: raise errors.AnsibleError("failed to transfer file from %s" % in_path) - sftp.close() def close(self): ''' terminate the connection ''' + if self.sftp is not None: + self.sftp.close() self.ssh.close()