<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 = /etc/ansible/ansible.cfg
  configured module search path = ['/usr/share/custom_modules']"><pre class="notranslate"><code class="notranslate">ansible 2.1.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/usr/share/custom_modules']
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="pipelining = True"><pre class="notranslate"><code class="notranslate">pipelining = True
</code></pre></div>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">CentOS Linux release 7.0.1406 (Core)</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">When using the synchronize module with become and delegate_to, user that initiated playbook (root) is used when trying to ssh to target host rather than the specified become_user.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<ol dir="auto">
<li>Create ansible task as shown below</li>
<li>Run playbook</li>
</ol>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="--- 
- hosts: hosta:hostb 
  gather_facts: no

  tasks:
    - name: Copy folder from one server to another
      synchronize:
        mode: push
        src: &quot;/tmp/foo/&quot;
        dest: &quot;/tmp/foo&quot;
      delegate_to: &quot;hosta&quot;
      become: yes
      become_user: app_user
      become_method: su"><pre class="notranslate"><code class="notranslate">--- 
- hosts: hosta:hostb 
  gather_facts: no

  tasks:
    - name: Copy folder from one server to another
      synchronize:
        mode: push
        src: "/tmp/foo/"
        dest: "/tmp/foo"
      delegate_to: "hosta"
      become: yes
      become_user: app_user
      become_method: su
</code></pre></div>
<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">/tmp/foo is synchronized from hosta to hostb as user app_user</p>
<h5 dir="auto">ACTUAL RESULTS</h5>


<p dir="auto">As shown below, tries to authenticate on target system as root user rather than app_user</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Too many authentication failures for root\r\nrsync: connection unexpectedly closed (0 bytes received so far) [sender]\nrsync error: unexplained error (code 255) at io.c(600) [sender=3.0.6]\n&quot;, &quot;rc&quot;: 255}"><pre class="notranslate"><code class="notranslate">Too many authentication failures for root\r\nrsync: connection unexpectedly closed (0 bytes received so far) [sender]\nrsync error: unexplained error (code 255) at io.c(600) [sender=3.0.6]\n", "rc": 255}
</code></pre></div>
<p dir="auto">I tested in 2.0.0.2 and worked ok, in 2.0.2.0 it didn't work, and does not work in latest 2.1.</p>
<p dir="auto">As a workaround, can add following option to synchronize module</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="rsync_opts: --rsh &quot;ssh -l app_user -i /app/home/app_user/.ssh/id_rs"><pre class="notranslate"><code class="notranslate">rsync_opts: --rsh "ssh -l app_user -i /app/home/app_user/.ssh/id_rs
</code></pre></div>
<p dir="auto">This forces the delegated machine to use the key/user already established when performing the rsync.</p>
<h5 dir="auto">ISSUE TYPE</h5>
<p dir="auto">Bug Report</p>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">synchronize module</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.0.0"><pre class="notranslate"><code class="notranslate">ansible 2.1.0.0
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<p dir="auto">host_key_checking = False</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">Fedora 23</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">Doing a remote-to-remote push requires using delegate_to. When using synchronize on a host with ansible_user set, and using delegate_to to copy from a second host, Ansible fails to set the remote user for the destination. The remote user is set correctly when delegate_to is removed.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<p dir="auto">The task that triggers the bug:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="      - synchronize:
          src: /home/gemserver/gems/gems
          dest: /var/geminabox/gems/gems
          delete: yes
        delegate_to: &quot;{{ groups['gemserver_master'][0] }}&quot;"><pre class="notranslate"><code class="notranslate">      - synchronize:
          src: /home/gemserver/gems/gems
          dest: /var/geminabox/gems/gems
          delete: yes
        delegate_to: "{{ groups['gemserver_master'][0] }}"
</code></pre></div>
<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">When running with -vvv, the "dest" value should report as "user@host:/var/geminabox/gems/gems",</p>
<h5 dir="auto">ACTUAL RESULTS</h5>
<p dir="auto">dest is set to just "host:/var/geminabox/gems/gems" (no user@) when delegate_to is present, resulting in being unable to sync.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="fatal: [111.111.111.111 -&gt; gemserver-master]: FAILED! =&gt; {&quot;changed&quot;: false, &quot;cmd&quot;: &quot;/usr/bin/rsync --delay-updates -F --compress --dry-run --delete-after --archive --rsh 'ssh  -S none -o StrictHostKeyChecking=no' --out-format='&lt;&lt;CHANGED&gt;&gt;%i %n%L' \&quot;/home/gemserver/gems/gems\&quot; \&quot;111.111.111.111:/var/geminabox/gems/gems\&quot;&quot;, &quot;failed&quot;: true, &quot;invocation&quot;: {&quot;module_args&quot;: {&quot;_local_rsync_path&quot;: &quot;rsync&quot;, &quot;_substitute_controller&quot;: false, &quot;archive&quot;: true, &quot;checksum&quot;: false, &quot;compress&quot;: true, &quot;copy_links&quot;: null, &quot;delete&quot;: true, &quot;dest&quot;: &quot;111.111.111.111:/var/geminabox/gems/gems&quot;, &quot;dest_port&quot;: 22, &quot;dirs&quot;: false, &quot;existing_only&quot;: false, &quot;group&quot;: null, &quot;links&quot;: null, &quot;mode&quot;: &quot;push&quot;, &quot;owner&quot;: null, &quot;partial&quot;: false, &quot;perms&quot;: null, &quot;private_key&quot;: null, &quot;recursive&quot;: null, &quot;rsync_opts&quot;: null, &quot;rsync_path&quot;: null, &quot;rsync_timeout&quot;: 0, &quot;set_remote_user&quot;: true, &quot;src&quot;: &quot;/home/gemserver/gems/gems&quot;, &quot;ssh_args&quot;: null, &quot;times&quot;: null, &quot;verify_host&quot;: false}}, &quot;msg&quot;: &quot;Permission denied (publickey,gssapi-keyex,gssapi-with-mic).\r\nrsync: connection unexpectedly closed (0 bytes received so far) [sender]\nrsync error: unexplained error (code 255) at io.c(605) [sender=3.0.9]\n&quot;, &quot;rc&quot;: 255}"><pre class="notranslate"><code class="notranslate">fatal: [111.111.111.111 -&gt; gemserver-master]: FAILED! =&gt; {"changed": false, "cmd": "/usr/bin/rsync --delay-updates -F --compress --dry-run --delete-after --archive --rsh 'ssh  -S none -o StrictHostKeyChecking=no' --out-format='&lt;&lt;CHANGED&gt;&gt;%i %n%L' \"/home/gemserver/gems/gems\" \"111.111.111.111:/var/geminabox/gems/gems\"", "failed": true, "invocation": {"module_args": {"_local_rsync_path": "rsync", "_substitute_controller": false, "archive": true, "checksum": false, "compress": true, "copy_links": null, "delete": true, "dest": "111.111.111.111:/var/geminabox/gems/gems", "dest_port": 22, "dirs": false, "existing_only": false, "group": null, "links": null, "mode": "push", "owner": null, "partial": false, "perms": null, "private_key": null, "recursive": null, "rsync_opts": null, "rsync_path": null, "rsync_timeout": 0, "set_remote_user": true, "src": "/home/gemserver/gems/gems", "ssh_args": null, "times": null, "verify_host": false}}, "msg": "Permission denied (publickey,gssapi-keyex,gssapi-with-mic).\r\nrsync: connection unexpectedly closed (0 bytes received so far) [sender]\nrsync error: unexplained error (code 255) at io.c(605) [sender=3.0.9]\n", "rc": 255}
</code></pre></div>
<p dir="auto">(IP address replaced with 111.111.111.111)</p>