<h5 dir="auto">ISSUE TYPE</h5>

<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">ANSIBLE VERSION</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.1.0.0
  config file = /path/to/whatever/ansible.cfg
  configured module search path = Default w/o overrides"><pre class="notranslate"><code class="notranslate">ansible 2.1.0.0
  config file = /path/to/whatever/ansible.cfg
  configured module search path = Default w/o overrides
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[ssh_connection]
pipelining=True"><pre class="notranslate"><code class="notranslate">[ssh_connection]
pipelining=True
</code></pre></div>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">N/A</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">Unix domain socket created by ansible was too long, therefore ssh fails.<br>
The error message is very vague:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="this-is-a-long-hostname.example.org | UNREACHABLE! =&gt; {
    &quot;changed&quot;: false,
    &quot;msg&quot;: &quot;Failed to connect to the host via ssh.&quot;,
    &quot;unreachable&quot;: true
}"><pre class="notranslate"><code class="notranslate">this-is-a-long-hostname.example.org | UNREACHABLE! =&gt; {
    "changed": false,
    "msg": "Failed to connect to the host via ssh.",
    "unreachable": true
}
</code></pre></div>
<p dir="auto">Giving the same ssh command as ansible, the error was more descriptive:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="unix_listener: &quot;/Users/user12/.ansible/cp/ansible-ssh-this-is-a-long-hostname.example.org-1022-user12345.ulAxrSDBy3jA13KO&quot; too long for Unix domain socket"><pre class="notranslate"><code class="notranslate">unix_listener: "/Users/user12/.ansible/cp/ansible-ssh-this-is-a-long-hostname.example.org-1022-user12345.ulAxrSDBy3jA13KO" too long for Unix domain socket
</code></pre></div>
<p dir="auto">I was able to solve this by putting in my <code class="notranslate">ansible.cfg</code></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="control_path = %(directory)s/%%h-%%r"><pre class="notranslate"><code class="notranslate">control_path = %(directory)s/%%h-%%r
</code></pre></div>
<p dir="auto">The socket name that ansible sets is clearly way too long. This means that, as of now, long hostnames don't work with Ansible, and it can be quite restricting.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<ul dir="auto">
<li>Have a long hostname in your inventory (e.g. <code class="notranslate">this-is-a-long-hostname.example.org</code>)</li>
<li>Try a simple ping command (with <code class="notranslate">ansible -vvvvvvvvvvvvv -m ping</code> to that host)</li>
</ul>
<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">You can connect to the machine</p>
<h5 dir="auto">ACTUAL RESULTS</h5>
<ul dir="auto">
<li>You cannot connect to the machine</li>
<li>SSH error is very vague (maybe addressed by <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="164580976" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible/issues/16649" data-hovercard-type="pull_request" data-hovercard-url="/ansible/ansible/pull/16649/hovercard" href="https://github.com/ansible/ansible/pull/16649">#16649</a> )</li>
</ul>
<h5 dir="auto">ISSUE TYPE</h5>
<p dir="auto">Feature Idea</p>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">ssh control persist</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<p dir="auto">2.0</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">When trying to use the ec2 plugin, ssh fails with this error:</p>
<p dir="auto"><code class="notranslate">SSH Error: unix_listener: "/Users/luke/.ansible/cp/ansible-ssh-ec2-255-255-255-255.compute-1.amazonaws.com-22-ubuntu.CErvOvRE5U0urCgm" too long for Unix domain socket</code></p>
<p dir="auto">Here's the full example:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ ansible -vvvv -i ec2.py -u ubuntu us-east-1 -m ping
&lt;ec2-255-255-255-255.compute-1.amazonaws.com&gt; ESTABLISH CONNECTION FOR USER: ubuntu
&lt;ec2-255-255-255-255.compute-1.amazonaws.com&gt; REMOTE_MODULE ping
&lt;ec2-255-255-255-255.compute-1.amazonaws.com&gt; EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath=&quot;/Users/luke/.ansible/cp/ansible-ssh-%h-%p-%r&quot; -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 ec2-255-255-255-255.compute-1.amazonaws.com /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1436458336.4-21039895766180 &amp;&amp; chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1436458336.4-21039895766180 &amp;&amp; echo $HOME/.ansible/tmp/ansible-tmp-1436458336.4-21039895766180'
ec2-255-255-255-255.compute-1.amazonaws.com | FAILED =&gt; SSH Error: unix_listener: &quot;/Users/luke/.ansible/cp/ansible-ssh-ec2-255-255-255-255.compute-1.amazonaws.com-22-ubuntu.CErvOvRE5U0urCgm&quot; too long for Unix domain socket
    while connecting to 255.255.255.255:22
It is sometimes useful to re-run the command using -vvvv, which prints SSH debug output to help diagnose the issue."><pre class="notranslate"><code class="notranslate">$ ansible -vvvv -i ec2.py -u ubuntu us-east-1 -m ping
&lt;ec2-255-255-255-255.compute-1.amazonaws.com&gt; ESTABLISH CONNECTION FOR USER: ubuntu
&lt;ec2-255-255-255-255.compute-1.amazonaws.com&gt; REMOTE_MODULE ping
&lt;ec2-255-255-255-255.compute-1.amazonaws.com&gt; EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/Users/luke/.ansible/cp/ansible-ssh-%h-%p-%r" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 ec2-255-255-255-255.compute-1.amazonaws.com /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1436458336.4-21039895766180 &amp;&amp; chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1436458336.4-21039895766180 &amp;&amp; echo $HOME/.ansible/tmp/ansible-tmp-1436458336.4-21039895766180'
ec2-255-255-255-255.compute-1.amazonaws.com | FAILED =&gt; SSH Error: unix_listener: "/Users/luke/.ansible/cp/ansible-ssh-ec2-255-255-255-255.compute-1.amazonaws.com-22-ubuntu.CErvOvRE5U0urCgm" too long for Unix domain socket
    while connecting to 255.255.255.255:22
It is sometimes useful to re-run the command using -vvvv, which prints SSH debug output to help diagnose the issue.
</code></pre></div>
<p dir="auto">I've changed some of the sensitive info in here like the IP etc.</p>