From 9b7d782abbfd10cd7a147b9396e3129e3ed5f2d4 Mon Sep 17 00:00:00 2001 From: graywulf Date: Thu, 30 Jun 2016 16:39:30 -0700 Subject: [PATCH] Ignore broken pipe errors if the sshpass process has exited (#16515) This fix prevents a broken pipe exception from occurring when password-less SSH is configured and the sshpass process exits and closes the pipe before the password is written to the pipe. --- lib/ansible/plugins/connection/ssh.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/ansible/plugins/connection/ssh.py b/lib/ansible/plugins/connection/ssh.py index 16f086b3037..3add4c1a839 100644 --- a/lib/ansible/plugins/connection/ssh.py +++ b/lib/ansible/plugins/connection/ssh.py @@ -19,6 +19,7 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type +import errno import fcntl import os import pipes @@ -346,7 +347,12 @@ class Connection(ConnectionBase): if self._play_context.password: os.close(self.sshpass_pipe[0]) - os.write(self.sshpass_pipe[1], "{0}\n".format(to_bytes(self._play_context.password))) + try: + os.write(self.sshpass_pipe[1], "{0}\n".format(to_bytes(self._play_context.password))) + except OSError as e: + # Ignore broken pipe errors if the sshpass process has exited. + if e.errno != errno.EPIPE or p.poll() is None: + raise os.close(self.sshpass_pipe[1]) ## SSH state machine