From dd71469bb7745601400a3bb00b89f490b2bced66 Mon Sep 17 00:00:00 2001 From: Andrea Tartaglia Date: Wed, 7 Sep 2016 16:41:43 +0100 Subject: [PATCH] Added option to change ssh executable path (#17377) --- lib/ansible/constants.py | 1 + lib/ansible/executor/task_executor.py | 3 ++- lib/ansible/plugins/connection/ssh.py | 11 +++++++---- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/ansible/constants.py b/lib/ansible/constants.py index 1adb31c808a..589e006d384 100644 --- a/lib/ansible/constants.py +++ b/lib/ansible/constants.py @@ -280,6 +280,7 @@ ANSIBLE_SSH_ARGS = get_config(p, 'ssh_connection', 'ssh_args', 'AN ANSIBLE_SSH_CONTROL_PATH = get_config(p, 'ssh_connection', 'control_path', 'ANSIBLE_SSH_CONTROL_PATH', "%(directory)s/ansible-ssh-%%h-%%p-%%r") ANSIBLE_SSH_PIPELINING = get_config(p, 'ssh_connection', 'pipelining', 'ANSIBLE_SSH_PIPELINING', False, boolean=True) ANSIBLE_SSH_RETRIES = get_config(p, 'ssh_connection', 'retries', 'ANSIBLE_SSH_RETRIES', 0, integer=True) +ANSIBLE_SSH_EXECUTABLE = get_config(p, 'ssh_connection', 'ssh_executable', 'ANSIBLE_SSH_EXECUTABLE', 'ssh') PARAMIKO_RECORD_HOST_KEYS = get_config(p, 'paramiko_connection', 'record_host_keys', 'ANSIBLE_PARAMIKO_RECORD_HOST_KEYS', True, boolean=True) PARAMIKO_PROXY_COMMAND = get_config(p, 'paramiko_connection', 'proxy_command', 'ANSIBLE_PARAMIKO_PROXY_COMMAND', None) diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index 91da5d3b04b..13906224b42 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -667,7 +667,8 @@ class TaskExecutor: else: # see if SSH can support ControlPersist if not use paramiko try: - cmd = subprocess.Popen(['ssh','-o','ControlPersist'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + ssh_executable = C.ANSIBLE_SSH_EXECUTABLE + cmd = subprocess.Popen([ssh_executable, '-o', 'ControlPersist'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) (out, err) = cmd.communicate() err = to_text(err) if u"Bad configuration option" in err or u"Usage:" in err: diff --git a/lib/ansible/plugins/connection/ssh.py b/lib/ansible/plugins/connection/ssh.py index fd99ccdef0b..ac34e8fc88b 100644 --- a/lib/ansible/plugins/connection/ssh.py +++ b/lib/ansible/plugins/connection/ssh.py @@ -144,7 +144,7 @@ class Connection(ConnectionBase): if self._play_context.verbosity > 3: self._command += ['-vvv'] - elif binary == 'ssh': + elif binary == C.ANSIBLE_SSH_EXECUTABLE: # Older versions of ssh (e.g. in RHEL 6) don't accept sftp -q. self._command += ['-q'] @@ -568,10 +568,12 @@ class Connection(ConnectionBase): # python interactive-mode but the modules are not compatible with the # interactive-mode ("unexpected indent" mainly because of empty lines) + ssh_executable = C.ANSIBLE_SSH_EXECUTABLE + if not in_data and sudoable: - args = ('ssh', '-tt', self.host, cmd) + args = (ssh_executable, '-tt', self.host, cmd) else: - args = ('ssh', self.host, cmd) + args = (ssh_executable, self.host, cmd) cmd = self._build_command(*args) (returncode, stdout, stderr) = self._run(cmd, in_data, sudoable=sudoable) @@ -682,7 +684,8 @@ class Connection(ConnectionBase): # TODO: reenable once winrm issues are fixed # temporarily disabled as we are forced to currently close connections after every task because of winrm # if self._connected and self._persistent: - # cmd = self._build_command('ssh', '-O', 'stop', self.host) + # ssh_executable = C.ANSIBLE_SSH_EXECUTABLE + # cmd = self._build_command(ssh_executable, '-O', 'stop', self.host) # # cmd = map(to_bytes, cmd) # p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)