diff options
author | Alberto Murillo <alberto.murillo.silva@intel.com> | 2016-11-26 16:55:38 -0600 |
---|---|---|
committer | James Cammarata <jimi@sngx.net> | 2016-11-26 17:01:53 -0600 |
commit | b9a1b2836a76ad0ee039b92db8fd4f7fbeecf1c0 (patch) | |
tree | 12ba9f342ca82fdf63d7f7c802edbe9c8cda186a | |
parent | 8dee7f31384652fb145484c8019b9d911773d8eb (diff) | |
download | ansible-b9a1b2836a76ad0ee039b92db8fd4f7fbeecf1c0.tar.gz |
Fix ssh plugin to correctly fetch files when using scp (#18614)
Fetch module uses fetch_file() from plugin/connection/ssh.py to
retrieve files from the remote hosts which in turns uses
_file_transport_command(self, in_path, out_path, sftp_action) being
sftp_action = 'get'
When using scp rather than sftp, sftp_action variable is not used
and the scp command is formed in a way that the file is always
sent to the remote machine
This patch fixes _file_transport_command() to correctly form the scp
swaping src and dest if sftp_action is 'get'
Bug introduced at 8e47b9b
Fixes #18603
Signed-off-by: Alberto Murillo Silva <alberto.murillo.silva@intel.com>
(cherry picked from commit ec2521f6af6730c34e01f3162f0af89c5625dcae)
-rw-r--r-- | lib/ansible/plugins/connection/ssh.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/ansible/plugins/connection/ssh.py b/lib/ansible/plugins/connection/ssh.py index 0c18b983a5..80a9fccb55 100644 --- a/lib/ansible/plugins/connection/ssh.py +++ b/lib/ansible/plugins/connection/ssh.py @@ -628,7 +628,10 @@ class Connection(ConnectionBase): cmd = self._build_command('sftp', to_bytes(host)) in_data = u"{0} {1} {2}\n".format(sftp_action, pipes.quote(in_path), pipes.quote(out_path)) elif method == 'scp': - cmd = self._build_command('scp', in_path, u'{0}:{1}'.format(host, pipes.quote(out_path))) + if sftp_action == 'get': + cmd = self._build_command('scp', u'{0}:{1}'.format(host, pipes.quote(out_path)), in_path) + else: + cmd = self._build_command('scp', in_path, u'{0}:{1}'.format(host, pipes.quote(out_path))) in_data = None in_data = to_bytes(in_data, nonstring='passthru') |