<p dir="auto"><strong>Ansible version</strong></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.0.0 (stable-2.0 b9fbfaf64e) last updated 2015/12/03 08:27:24 (GMT +300)
  lib/ansible/modules/core: (detached HEAD 273112c56d) last updated 2015/11/24 09:00:04 (GMT +300)
  lib/ansible/modules/extras: (detached HEAD e46e2e1d6f) last updated 2015/11/24 09:00:04 (GMT +300)"><pre class="notranslate"><code class="notranslate">ansible 2.0.0 (stable-2.0 b9fbfaf64e) last updated 2015/12/03 08:27:24 (GMT +300)
  lib/ansible/modules/core: (detached HEAD 273112c56d) last updated 2015/11/24 09:00:04 (GMT +300)
  lib/ansible/modules/extras: (detached HEAD e46e2e1d6f) last updated 2015/11/24 09:00:04 (GMT +300)
</code></pre></div>
<p dir="auto"><strong>Summary</strong></p>
<p dir="auto">The playbook that worked fine a couple of days ago is now failing with</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="fatal: [trusty]: UNREACHABLE! =&gt; {&quot;changed&quot;: false, &quot;msg&quot;: &quot;ERROR! SSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issue&quot;, &quot;unreachable&quot;: true}"><pre class="notranslate"><code class="notranslate">fatal: [trusty]: UNREACHABLE! =&gt; {"changed": false, "msg": "ERROR! SSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issue", "unreachable": true}
</code></pre></div>
<p dir="auto">in the middle of the play.</p>
<p dir="auto">The task in question looks like this:</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- name: user for accepting pushed backups on the backup buddy
  user: name=&quot;{{ backup_user }}&quot; state=present
  delegate_to: &quot;{{ backup_buddy }}&quot;
  when: backup_buddy != &quot;&quot;
  tags: [ backups, user, FAIL ]"><pre class="notranslate">- <span class="pl-ent">name</span>: <span class="pl-s">user for accepting pushed backups on the backup buddy</span>
  <span class="pl-ent">user</span>: <span class="pl-s">name="{{ backup_user }}" state=present</span>
  <span class="pl-ent">delegate_to</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ backup_buddy }}<span class="pl-pds">"</span></span>
  <span class="pl-ent">when</span>: <span class="pl-s">backup_buddy != ""</span>
  <span class="pl-ent">tags</span>: <span class="pl-s">[ backups, user, FAIL ]</span></pre></div>
<p dir="auto">The failure happens on host <code class="notranslate">trusty</code>, which is a Vagrant VM.  <code class="notranslate">host_vars/trusty</code> sets <code class="notranslate">backup_buddy</code> to <code class="notranslate">precise</code>, which is a different Vagrant VM.  The inventory file is generated by Vagrant's Ansible provisioner and looks like this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="trusty ansible_ssh_host=127.0.0.1 ansible_ssh_port=2200 ansible_ssh_private_key_file=/home/mg/src/deployments/provisioning/.vagrant/machines/trusty/virtualbox/private_key
precise ansible_ssh_host=127.0.0.1 ansible_ssh_port=2222 ansible_ssh_private_key_file=/home/mg/src/deployments/provisioning/.vagrant/machines/precise/virtualbox/private_key"><pre class="notranslate"><code class="notranslate">trusty ansible_ssh_host=127.0.0.1 ansible_ssh_port=2200 ansible_ssh_private_key_file=/home/mg/src/deployments/provisioning/.vagrant/machines/trusty/virtualbox/private_key
precise ansible_ssh_host=127.0.0.1 ansible_ssh_port=2222 ansible_ssh_private_key_file=/home/mg/src/deployments/provisioning/.vagrant/machines/precise/virtualbox/private_key
</code></pre></div>
<p dir="auto">The SSH command shown in <code class="notranslate">-vvvv</code> mode looks like this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;127.0.0.1&gt; ESTABLISH SSH CONNECTION FOR USER: None
&lt;127.0.0.1&gt; SSH: EXEC ssh -C -vvv -o ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o Port=2222 -o 'IdentityFile=&quot;/home/mg/src/deployments/provisioning/.vagrant/machines/precise/virtualbox/private_key&quot;' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/mg/.ansible/cp/ansible-ssh-%h-%p-%r -tt 127.0.0.1 (umask 22 &amp;&amp; mkdir -p &quot;`echo $HOME/.ansible/tmp/ansible-tmp-1449125747.77-81162502568054`&quot; &amp;&amp; echo &quot;`echo $HOME/.ansible/tmp/ansible-tmp-1449125747.77-81162502568054`&quot;)"><pre class="notranslate"><code class="notranslate">&lt;127.0.0.1&gt; ESTABLISH SSH CONNECTION FOR USER: None
&lt;127.0.0.1&gt; SSH: EXEC ssh -C -vvv -o ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o Port=2222 -o 'IdentityFile="/home/mg/src/deployments/provisioning/.vagrant/machines/precise/virtualbox/private_key"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/mg/.ansible/cp/ansible-ssh-%h-%p-%r -tt 127.0.0.1 (umask 22 &amp;&amp; mkdir -p "`echo $HOME/.ansible/tmp/ansible-tmp-1449125747.77-81162502568054`" &amp;&amp; echo "`echo $HOME/.ansible/tmp/ansible-tmp-1449125747.77-81162502568054`")
</code></pre></div>
<p dir="auto">and the ssh output is long and boring, but shows this</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="...
debug1: Authenticating to 127.0.0.1:2222 as 'mgedmin'
...
Permission denied (publickey,password)."><pre class="notranslate"><code class="notranslate">...
debug1: Authenticating to 127.0.0.1:2222 as 'mgedmin'
...
Permission denied (publickey,password).
</code></pre></div>
<p dir="auto"><code class="notranslate">mgedmin</code> is my username on the host.  There's no <code class="notranslate">mgedmin</code> user in the Vagrant VM.  My ansible.cfg defines</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="remote_user = vagrant"><pre class="notranslate"><code class="notranslate">remote_user = vagrant
</code></pre></div>
<p dir="auto">and that's what I expect to be used.</p>
<p dir="auto">Issue Type: Bug Report (2.0 regression)<br>
Ansible Version: 2.0.0 (devel)<br>
Ansible Configuration: default<br>
Environment: Ubuntu 14.04<br>
Summary:<br>
delegate_to does not use user specified with remote_user.</p>
<p dir="auto">Steps To Reproduce:<br>
Following playbook works correctly on 1.9.4 with output root and on devel it outputs normal user.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
---
- hosts:
    - test-vm
  become: yes

  tasks:
  - command: whoami
    register: whoami
    delegate_to: &quot;test-vm2&quot;
    remote_user: root
    become: false

  - debug: msg=&quot;{{ whoami.stdout }}&quot;"><pre class="notranslate"><code class="notranslate">
---
- hosts:
    - test-vm
  become: yes

  tasks:
  - command: whoami
    register: whoami
    delegate_to: "test-vm2"
    remote_user: root
    become: false

  - debug: msg="{{ whoami.stdout }}"
</code></pre></div>
<p dir="auto">Expected Results:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ok: [test] =&gt; {
    &quot;changed&quot;: false, 
    &quot;invocation&quot;: {
        &quot;module_args&quot;: {
            &quot;msg&quot;: &quot;root&quot;
        }, 
        &quot;module_name&quot;: &quot;debug&quot;
    }, 
    &quot;msg&quot;: &quot;root
}
"><pre class="notranslate"><code class="notranslate">ok: [test] =&gt; {
    "changed": false, 
    "invocation": {
        "module_args": {
            "msg": "root"
        }, 
        "module_name": "debug"
    }, 
    "msg": "root
}

</code></pre></div>
<p dir="auto">Actual Results:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ok: [test] =&gt; {
    &quot;changed&quot;: false, 
    &quot;invocation&quot;: {
        &quot;module_args&quot;: {
            &quot;msg&quot;: &quot;username&quot;
        }, 
        &quot;module_name&quot;: &quot;debug&quot;
    }, 
    &quot;msg&quot;: &quot;username&quot;
}"><pre class="notranslate"><code class="notranslate">ok: [test] =&gt; {
    "changed": false, 
    "invocation": {
        "module_args": {
            "msg": "username"
        }, 
        "module_name": "debug"
    }, 
    "msg": "username"
}
</code></pre></div>