<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">SSH connection plugin</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.3.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4]"><pre class="notranslate"><code class="notranslate">ansible 2.3.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4]
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<p dir="auto">Default configuration.</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">Ubuntu 14.04.5<br>
Kernel 3.13.0-83-generic<br>
Ansible installed via pip</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">Looks like SSH connection sharing is broken. I have one single server defined in inventory twice – with the same hostname, but different alias.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<ol dir="auto">
<li>Any playbook.</li>
<li>Inventory like:</li>
</ol>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="server.io-8721 ansible_host=server.io
server.io-d4f2 ansible_host=server.io"><pre class="notranslate"><code class="notranslate">server.io-8721 ansible_host=server.io
server.io-d4f2 ansible_host=server.io
</code></pre></div>
<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">Setup task success.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>
<p dir="auto">On <code class="notranslate">setup</code> task I get:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="TASK [setup] *******************************************************************
fatal: [server.io-8721]: UNREACHABLE! =&gt; {&quot;changed&quot;: false, &quot;msg&quot;: &quot;Failed to connect to the host via ssh: Shared connection to server.io closed.\r\n&quot;, &quot;unreachable&quot;: true}

msg: Failed to connect to the host via ssh: Shared connection to server.io closed.

fatal: [server.io-d4f2]: UNREACHABLE! =&gt; {&quot;changed&quot;: false, &quot;msg&quot;: &quot;Failed to connect to the host via ssh: Shared connection to server.io closed.\r\n&quot;, &quot;unreachable&quot;: true}

msg: Failed to connect to the host via ssh: Shared connection to server.io closed."><pre class="notranslate"><code class="notranslate">TASK [setup] *******************************************************************
fatal: [server.io-8721]: UNREACHABLE! =&gt; {"changed": false, "msg": "Failed to connect to the host via ssh: Shared connection to server.io closed.\r\n", "unreachable": true}

msg: Failed to connect to the host via ssh: Shared connection to server.io closed.

fatal: [server.io-d4f2]: UNREACHABLE! =&gt; {"changed": false, "msg": "Failed to connect to the host via ssh: Shared connection to server.io closed.\r\n", "unreachable": true}

msg: Failed to connect to the host via ssh: Shared connection to server.io closed.
</code></pre></div>
<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">ansible-playbook  / SSH connection type</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.1.1.0
  config file = 
  configured module search path = Default w/o overrides"><pre class="notranslate"><code class="notranslate">ansible 2.1.1.0
  config file = 
  configured module search path = Default w/o overrides
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<p dir="auto">No custom config present</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# OracleLinux 7.2
# cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 7.2 (Maipo)"><pre class="notranslate"><code class="notranslate"># OracleLinux 7.2
# cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 7.2 (Maipo)
</code></pre></div>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">I'm seeing random (but persistent) failures in ansible-playbook around the setup task failing due to what seems to be SSH multiplexing.</p>
<p dir="auto">We run a playbook comprised of about 15 roles, each with a multitude of tasks. Almost without fail, each run of the playbook will fail at some random point during the "setup" stage, at which point it dumps the contents of the facts discovered about the target node and continues on to the next node. I can reproduce this with a very simple playbook, which I will link below[0] along with the error[1].</p>
<p dir="auto">Looking in the error output, you can see the following type of output: "mux_client_read_packet: read header failed: Broken pipe". I can reproduce this using a very simple SSH command, trimmed down from what Ansible is using:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# ssh -vvv -o ControlMaster=auto -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r database02 hostname
...
debug2: set_control_persist_exit_time: schedule exit in 60 seconds
debug3: mux_client_read_packet: read header failed: Broken pipe
debug2: Received exit status from master 0"><pre class="notranslate"><code class="notranslate"># ssh -vvv -o ControlMaster=auto -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r database02 hostname
...
debug2: set_control_persist_exit_time: schedule exit in 60 seconds
debug3: mux_client_read_packet: read header failed: Broken pipe
debug2: Received exit status from master 0
</code></pre></div>
<p dir="auto">If I remove the -o ControlPath from the above, or clean out ~/.ansible/cp, the ssh command works fine, but a re-run of ansible-playbook seems to recreate the faulty socket (at a non deterministic point in the playbook).</p>
<p dir="auto">I have played with <em>many</em> different combinations of ssh_args in ~/.ansible.cfg, including higher values for ControlPersist, ServerAliveInterval, ServerAliveCountMax, changing ControlPath, and enabling pipelining, none seem to make a difference.</p>
<p dir="auto">Can anyone provide any other possible workarounds or ways I can debug this? Is there a way to force Ansible to disable ControlPersist?</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible-playbook -i ~/multinode test.yml -vvvv"><pre class="notranslate"><code class="notranslate">ansible-playbook -i ~/multinode test.yml -vvvv
</code></pre></div>
<p dir="auto">[0] <a href="https://gist.github.com/brk3/1562e595a04d85b9df04bac9c8054273">https://gist.github.com/brk3/1562e595a04d85b9df04bac9c8054273</a> (playbook: test.yml)<br>
[1] <a href="https://gist.github.com/brk3/f06da830405d0cb3ffeed59d2901e5a9">https://gist.github.com/brk3/f06da830405d0cb3ffeed59d2901e5a9</a> (error output)<br>
[2] <a href="https://gist.github.com/brk3/7fe02114c804eef58a108c086d8cb26c">https://gist.github.com/brk3/7fe02114c804eef58a108c086d8cb26c</a> (inventory)</p>