ANSIBLE_SSH_USETTY configuration option (#33148)

* Allow the user to circumvent adding -tt on ssh commands to help aid in
debugging ssh related problems.
* Move config to the plugin
* Set version_added
* Change yaml section to "connection"
* Fix ssh unit tests
pull/33194/head
jctanner 7 years ago committed by GitHub
parent aa42a2680e
commit 218987eac1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -401,6 +401,10 @@
# only be disabled if your sftp version has problems with batch mode # only be disabled if your sftp version has problems with batch mode
#sftp_batch_mode = False #sftp_batch_mode = False
# The -tt argument is passed to ssh when pipelining is not enabled because sudo
# requires a tty by default.
#use_tty = True
[persistent_connection] [persistent_connection]
# Configures the persistent connection timeout value in seconds. This value is # Configures the persistent connection timeout value in seconds. This value is

@ -185,6 +185,15 @@ DOCUMENTATION = '''
env: [{name: ANSIBLE_SCP_IF_SSH}] env: [{name: ANSIBLE_SCP_IF_SSH}]
ini: ini:
- {key: scp_if_ssh, section: ssh_connection} - {key: scp_if_ssh, section: ssh_connection}
use_tty:
version_added: '2.5'
default: True
description: add -tt to ssh commands to force tty allocation
env: [{name: ANSIBLE_SSH_USETTY}]
ini:
- {key: usetty, section: ssh_connection}
type: boolean
yaml: {key: connection.usetty}
''' '''
import errno import errno
@ -957,7 +966,11 @@ class Connection(ConnectionBase):
ssh_executable = self._play_context.ssh_executable ssh_executable = self._play_context.ssh_executable
if not in_data and sudoable: # -tt can cause various issues in some environments so allow the user
# to disable it as a troubleshooting method.
use_tty = self.get_option('use_tty')
if not in_data and sudoable and use_tty:
args = (ssh_executable, '-tt', self.host, cmd) args = (ssh_executable, '-tt', self.host, cmd)
else: else:
args = (ssh_executable, self.host, cmd) args = (ssh_executable, self.host, cmd)

@ -80,6 +80,8 @@ class TestConnectionBaseClass(unittest.TestCase):
conn._build_command.return_value = 'ssh something something' conn._build_command.return_value = 'ssh something something'
conn._run = MagicMock() conn._run = MagicMock()
conn._run.return_value = (0, 'stdout', 'stderr') conn._run.return_value = (0, 'stdout', 'stderr')
conn.get_option = MagicMock()
conn.get_option.return_value = True
res, stdout, stderr = conn.exec_command('ssh') res, stdout, stderr = conn.exec_command('ssh')
res, stdout, stderr = conn.exec_command('ssh', 'this is some data') res, stdout, stderr = conn.exec_command('ssh', 'this is some data')
@ -538,6 +540,8 @@ class TestSSHConnectionRetries(object):
self.conn._build_command = MagicMock() self.conn._build_command = MagicMock()
self.conn._build_command.return_value = 'ssh' self.conn._build_command.return_value = 'ssh'
self.conn.get_option = MagicMock()
self.conn.get_option.return_value = True
return_code, b_stdout, b_stderr = self.conn.exec_command('ssh', 'some data') return_code, b_stdout, b_stderr = self.conn.exec_command('ssh', 'some data')
assert return_code == 0 assert return_code == 0
@ -563,6 +567,8 @@ class TestSSHConnectionRetries(object):
self.conn._build_command = MagicMock() self.conn._build_command = MagicMock()
self.conn._build_command.return_value = 'ssh' self.conn._build_command.return_value = 'ssh'
self.conn.get_option = MagicMock()
self.conn.get_option.return_value = True
pytest.raises(AnsibleConnectionFailure, self.conn.exec_command, 'ssh', 'some data') pytest.raises(AnsibleConnectionFailure, self.conn.exec_command, 'ssh', 'some data')
assert self.mock_popen.call_count == 10 assert self.mock_popen.call_count == 10
@ -575,6 +581,8 @@ class TestSSHConnectionRetries(object):
self.conn._build_command = MagicMock() self.conn._build_command = MagicMock()
self.conn._build_command.return_value = 'ssh' self.conn._build_command.return_value = 'ssh'
self.conn.get_option = MagicMock()
self.conn.get_option.return_value = True
self.mock_popen.side_effect = [Exception('bad')] * 10 self.mock_popen.side_effect = [Exception('bad')] * 10
pytest.raises(Exception, self.conn.exec_command, 'ssh', 'some data') pytest.raises(Exception, self.conn.exec_command, 'ssh', 'some data')

Loading…
Cancel
Save