diff options
author | Matt Martz <matt@sivel.net> | 2018-01-18 09:28:25 -0600 |
---|---|---|
committer | Toshio Kuratomi <a.badger@gmail.com> | 2018-01-18 09:33:08 -0800 |
commit | fb9e7a85b33a49583b86a339ff877fb4c82eb840 (patch) | |
tree | 41427822180deda4b63ef94be663badaee7698ed | |
parent | 794c531158e8db021d486015235357d7b9e93009 (diff) | |
download | ansible-fb9e7a85b33a49583b86a339ff877fb4c82eb840.tar.gz |
Ensure that the become password is written on py3 in the ssh connection plugin. Fixes #34727
(cherry picked from commit 29c1d5cb5d283c649a5bc30dce53b8e4875d01d3)
-rw-r--r-- | lib/ansible/plugins/connection/ssh.py | 3 | ||||
-rw-r--r-- | test/units/plugins/connection/test_ssh.py | 1 |
2 files changed, 4 insertions, 0 deletions
diff --git a/lib/ansible/plugins/connection/ssh.py b/lib/ansible/plugins/connection/ssh.py index 845612eb92..85f4c6571d 100644 --- a/lib/ansible/plugins/connection/ssh.py +++ b/lib/ansible/plugins/connection/ssh.py @@ -758,6 +758,9 @@ class Connection(ConnectionBase): if self._flags['become_prompt']: display.debug('Sending become_pass in response to prompt') stdin.write(to_bytes(self._play_context.become_pass) + b'\n') + # On python3 stdin is a BufferedWriter, and we don't have a guarantee + # that the write will happen without a flush + stdin.flush() self._flags['become_prompt'] = False state += 1 elif self._flags['become_success']: diff --git a/test/units/plugins/connection/test_ssh.py b/test/units/plugins/connection/test_ssh.py index 2ca4d93a8e..092ad70008 100644 --- a/test/units/plugins/connection/test_ssh.py +++ b/test/units/plugins/connection/test_ssh.py @@ -457,6 +457,7 @@ class TestSSHConnectionRun(object): self.mock_selector.get_map.side_effect = lambda: True return_code, b_stdout, b_stderr = self.conn._run("ssh", "this is input data") + self.mock_popen_res.stdin.flush.assert_called_once_with() assert return_code == 0 assert b_stdout == b'abc' assert b_stderr == b'123' |