<p dir="auto">This does not work (note the usage of localhost two times; I am running Vagrant (ssh port 2222) and within the vagrant box I am running a Docker container (ssh port 29007); this container has not been started yet ):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[hostvessels]
localhost ansible_ssh_user=core ansible_ssh_port=2222 ansible_ssh_private_key_file=/home/thijsterlouw/.vagrant.d/insecure_private_key

[containers]
localhost ansible_ssh_user=root ansible_ssh_port=29007 ansible_ssh_pass=password"><pre class="notranslate"><code class="notranslate">[hostvessels]
localhost ansible_ssh_user=core ansible_ssh_port=2222 ansible_ssh_private_key_file=/home/thijsterlouw/.vagrant.d/insecure_private_key

[containers]
localhost ansible_ssh_user=root ansible_ssh_port=29007 ansible_ssh_pass=password
</code></pre></div>
<p dir="auto">error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="TASK: [ensure container path for docker.sh] *********************************** 
fatal: [localhost] =&gt; Authentication failure."><pre class="notranslate"><code class="notranslate">TASK: [ensure container path for docker.sh] *********************************** 
fatal: [localhost] =&gt; Authentication failure.
</code></pre></div>
<p dir="auto">But this does work (note I renamed the first host):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[hostvessels]
coreos.vagrant ansible_ssh_user=core ansible_ssh_port=2222 ansible_ssh_private_key_file=/home/thijsterlouw/.vagrant.d/insecure_private_key

[containers]
localhost ansible_ssh_user=root ansible_ssh_port=29007 ansible_ssh_pass=password"><pre class="notranslate"><code class="notranslate">[hostvessels]
coreos.vagrant ansible_ssh_user=core ansible_ssh_port=2222 ansible_ssh_private_key_file=/home/thijsterlouw/.vagrant.d/insecure_private_key

[containers]
localhost ansible_ssh_user=root ansible_ssh_port=29007 ansible_ssh_pass=password
</code></pre></div>
<p dir="auto">Where coreos.vagrant is mapped in /etc/hosts to 127.0.0.1</p>
<p dir="auto">I am running this with</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible-playbook -i generated/servers.ini static/site.yml --tags=&quot;predeploy,deploy&quot;"><pre class="notranslate"><code class="notranslate">ansible-playbook -i generated/servers.ini static/site.yml --tags="predeploy,deploy"
</code></pre></div>
<p dir="auto">The container inside the Vagrant box is not yet running, but this should be ignored because I am only performing tasks that hit the hostvessels.</p>
<p dir="auto">Why does Ansible think the host is down, even though the appropriate ssh port is perfectly available. Looks like a bug to me.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible --version
ansible 1.4"><pre class="notranslate"><code class="notranslate">ansible --version
ansible 1.4
</code></pre></div>
<p dir="auto">This is duplicate of <a href="https://github.com/ansible/ansible/issues/5934" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible/issues/5934/hovercard">#5934</a>!</p>
<h5 dir="auto">Issue Type:</h5>
<p dir="auto">Bug Report</p>
<h5 dir="auto">Ansible Version:</h5>
<p dir="auto">1.9.4</p>
<h5 dir="auto">Ansible Configuration:</h5>
<p dir="auto">Original.</p>
<h5 dir="auto">Environment:</h5>
<p dir="auto">OS X Yosemite 10.10.5 (14F1021)</p>
<h5 dir="auto">Summary:</h5>
<p dir="auto">inventory</p>
<div class="highlight highlight-source-ini notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="[vagrant]
192.168.56.132 ansible_ssh_user=vagrant ansible_ssh_private_key_file=.vagrant/machines/default/virtualbox/private_key"><pre class="notranslate"><span class="pl-en">[vagrant]</span>
192.168.56.132 <span class="pl-k">ansible_ssh_user</span>=vagrant <span class="pl-k">ansible_ssh_private_key_file</span>=.vagrant/machines/default/virtualbox/private_key</pre></div>
<p dir="auto">provision.yml</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- hosts: all
  gather_facts: yes
  sudo: yes

tasks:
  - synchronize:
      src: ./
      dest: &quot;/var/lib/jenkins&quot;
      archive: no
      recursive: yes
    sudo: yes"><pre class="notranslate">- <span class="pl-ent">hosts</span>: <span class="pl-s">all</span>
  <span class="pl-ent">gather_facts</span>: <span class="pl-s">yes</span>
  <span class="pl-ent">sudo</span>: <span class="pl-s">yes</span>

<span class="pl-ent">tasks</span>:
  - <span class="pl-ent">synchronize</span>:
      <span class="pl-ent">src</span>: <span class="pl-s">./</span>
      <span class="pl-ent">dest</span>: <span class="pl-s"><span class="pl-pds">"</span>/var/lib/jenkins<span class="pl-pds">"</span></span>
      <span class="pl-ent">archive</span>: <span class="pl-s">no</span>
      <span class="pl-ent">recursive</span>: <span class="pl-s">yes</span>
    <span class="pl-ent">sudo</span>: <span class="pl-s">yes</span></pre></div>
<h5 dir="auto">Steps To Reproduce:</h5>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="ansible-playbook -vvvv provision.yml -i inventory --limit=vagrant"><pre class="notranslate">ansible-playbook -vvvv provision.yml -i inventory --limit=vagrant</pre></div>
<h5 dir="auto">Expected Results:</h5>
<p dir="auto"><code class="notranslate">synchronize</code> should not ask for a password, as other tasks do.</p>
<h5 dir="auto">Actual Results:</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;127.0.0.1&gt; EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1447416965.06-222404616716035 &amp;&amp; chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1447416965.06-222404616716035 &amp;&amp; echo $HOME/.ansible/tmp/ansible-tmp-1447416965.06-222404616716035']
&lt;127.0.0.1&gt; PUT /var/folders/72/r_f79s2974q5b59cq0f7c1wh0000gn/T/tmpTRff6u TO /Users/BR0kEN/.ansible/tmp/ansible-tmp-1447416965.06-222404616716035/synchronize
&lt;127.0.0.1&gt; EXEC ['/bin/sh', '-c', u'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /Users/BR0kEN/.ansible/tmp/ansible-tmp-1447416965.06-222404616716035/synchronize; rm -rf /Users/BR0kEN/.ansible/tmp/ansible-tmp-1447416965.06-222404616716035/ &gt;/dev/null 2&gt;&amp;1']
vagrant@192.168.56.132's password:"><pre class="notranslate"><code class="notranslate">&lt;127.0.0.1&gt; EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1447416965.06-222404616716035 &amp;&amp; chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1447416965.06-222404616716035 &amp;&amp; echo $HOME/.ansible/tmp/ansible-tmp-1447416965.06-222404616716035']
&lt;127.0.0.1&gt; PUT /var/folders/72/r_f79s2974q5b59cq0f7c1wh0000gn/T/tmpTRff6u TO /Users/BR0kEN/.ansible/tmp/ansible-tmp-1447416965.06-222404616716035/synchronize
&lt;127.0.0.1&gt; EXEC ['/bin/sh', '-c', u'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /Users/BR0kEN/.ansible/tmp/ansible-tmp-1447416965.06-222404616716035/synchronize; rm -rf /Users/BR0kEN/.ansible/tmp/ansible-tmp-1447416965.06-222404616716035/ &gt;/dev/null 2&gt;&amp;1']
vagrant@192.168.56.132's password:
</code></pre></div>
<h5 dir="auto">Debugging steps:</h5>
<p dir="auto">I've go to <code class="notranslate">ansible/modules/core/files/synchronize.py</code> and put <code class="notranslate">print(cmdstr)</code> before <code class="notranslate">(rc, out, err) = module.run_command(cmd)</code>. Module generated the next command:</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="rsync --delay-updates -F --compress --recursive --rsh 'ssh -i .vagrant/machines/default/virtualbox/private_key -S none -o StrictHostKeyChecking=no' --rsync-path=&quot;sudo rsync&quot; --out-format='&lt;&lt;CHANGED&gt;&gt;%i %n%L' &quot;/Users/BR0kEN/cibox/aae/provisioning/roles/cibox-jenkins/files/&quot; &quot;vagrant@192.168.56.132:/var/lib/jenkins&quot;"><pre class="notranslate">rsync --delay-updates -F --compress --recursive --rsh <span class="pl-s"><span class="pl-pds">'</span>ssh -i .vagrant/machines/default/virtualbox/private_key -S none -o StrictHostKeyChecking=no<span class="pl-pds">'</span></span> --rsync-path=<span class="pl-s"><span class="pl-pds">"</span>sudo rsync<span class="pl-pds">"</span></span> --out-format=<span class="pl-s"><span class="pl-pds">'</span>&lt;&lt;CHANGED&gt;&gt;%i %n%L<span class="pl-pds">'</span></span> <span class="pl-s"><span class="pl-pds">"</span>/Users/BR0kEN/cibox/aae/provisioning/roles/cibox-jenkins/files/<span class="pl-pds">"</span></span> <span class="pl-s"><span class="pl-pds">"</span>vagrant@192.168.56.132:/var/lib/jenkins<span class="pl-pds">"</span></span></pre></div>
<p dir="auto"><strong>And even more:</strong></p>
<p dir="auto">Open the <code class="notranslate">ansible/runner/__init__.py</code> and put <code class="notranslate">print(cmd)</code> before <code class="notranslate">res = self._low_level_exec_command(conn, cmd, tmp, become=self.become, sudoable=sudoable, in_data=in_data)</code>. Module generated something like:</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /Users/BR0kEN/.ansible/tmp/ansible-tmp-1447418694.04-11945943198607/synchronize; rm -rf /Users/BR0kEN/.ansible/tmp/ansible-tmp-1447418694.04-11945943198607/ &gt;/dev/null 2&gt;&amp;1"><pre class="notranslate">LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /Users/BR0kEN/.ansible/tmp/ansible-tmp-1447418694.04-11945943198607/synchronize<span class="pl-k">;</span> rm -rf /Users/BR0kEN/.ansible/tmp/ansible-tmp-1447418694.04-11945943198607/ <span class="pl-k">&gt;</span>/dev/null <span class="pl-k">2&gt;&amp;1</span></pre></div>
<p dir="auto">When I execute one of these raw commands, then everything fine.</p>