SSH encountered an unknown error (Broken Pipe)

December 26, 2015

I just setup a Babun environment on my Windows 10 workstation and installed vagrant&ansible.
While testing my complete setup I got an error while using multiple vagrant vms in an ansible playbook or ansible command.

Most of the time only 1 or even 0 hosts were reachable with ansible:

vagrant2 | UNREACHABLE! => {
"changed": false,
"msg": "ERROR! SSH encountered an unknown error. 
The output was:\nOpenSSH_6.8p1,    
OpenSSL 1.0.2a 19 Mar 2015\r\ndebug1: Reading configuration 
data    /home/Simon/.ssh/config\r\ndebug1: 
/home/Simon/.ssh/config line 
1: Applying options for     127.0.0.1\r\ndebug1: auto-mux: 
Trying existing master\r\ndebug2: fd 3 setting     
O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master 
version 4\r\ndebug3:     
mux_client_forwards: request forwardings: 0 local, 0 
remote\r\ndebug3:     mux_client_request_session: entering
\r\ndebug3: mux_client_request_alive:     entering\r\ndebug3: 
mux_client_request_alive: done pid = 8476\r\nmm_send_fd: 
sendmsg(2):     Broken pipe\r\nmux_client_request_session: 
send fds failed\r\n",
"unreachable": true
}



The reason for this is that ansible as a default overrides the SSH connection to use the following options:
-o ControlMaster=auto -o ControlPersist=60s -o ControlPath=”/home/devel/.ansible/cp/ansible-ssh-%h-%p-%r”

In a vagrant setup you do usually a port forwarding for SSH. In my case I forwarded from TCP 2222, 2200 and 2201 to TCP 22 on the specific vagrant VM. The OpenSSH ControlMaster functionality in conjunction with port forwarding is a bad idea. So I had to prevent ansible using SSH ControlMaster with the following parameters in my ansible.cfg:

[ssh_connection]
ssh_args = -o ControlMaster=no



After changing the ansible.cfg all worked like a charm:

{ playbooks } » ansible all -a "date" ~/scripts/playbooks
vagrant3 | SUCCESS | rc=0 >>
Fri Dec 25 23:15:08 UTC 2015

vagrant1 | SUCCESS | rc=0 >>
Fri Dec 25 23:15:09 UTC 2015

vagrant2 | SUCCESS | rc=0 >>
Fri Dec 25 23:15:09 UTC 2015
Back...