title: How to run rsync using ansible playbook
body: <p>This is part of my ansible playbook</p>
  <pre><code>    - name: Create a new regular user with sudo privileges
        user:
          name: &quot;{{ create_user }}&quot;
          state: present
          groups: wheel
          append: true
          create_home: true
          shell: /bin/bash
  
      - name: Execute rsync command so the new user has the same authorized keys as root user
        ansible.builtin.shell: rsync --archive --chown\=={{ create_user }}:{{ create_user }} ~/.ssh /home/{{ create_user }}
  
      - name: Set authorized key for remote user
        authorized_key:
          user: &quot;{{ create_user }}&quot;
          state: present
          key: &quot;{{ copy_local_key }}&quot;
  </code></pre>
  <p>I have tested the original rsync command which is run at the target node as <code>root</code></p>
  <p><code>rsync --archive --chown\=sammy:sammy ~/.ssh /home/sammy</code></p>
  <p>This was definitely working if I had done this manually as <code>root</code> at the target node.</p>
  <p>The error message I got was</p>
  <pre><code>TASK [Create a new regular user with sudo privileges] **************************
  changed: [server1]
  
  TASK [Execute rsync command so the new user has the same authorized keys as root user] ***
  fatal: [server1]: FAILED! =&gt; {&quot;changed&quot;: false, &quot;msg&quot;: &quot;Unsupported parameters for (command) module: --chown\\= Supported parameters include: _raw_params, _uses_shell, argv, chdir, creates, executable, removes, stdin, stdin_add_newline, strip_empty_ends, warn&quot;}
  
  PLAY RECAP *********************************************************************
  server1                    : ok=5    changed=4    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0
  </code></pre>
  <p>My ansible version when I run <code>ansible --version</code></p>
  <pre><code>ansible 2.9.6
    config file = /etc/ansible/ansible.cfg
    configured module search path = ['/home/sammy/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
    ansible python module location = /usr/lib/python3/dist-packages/ansible
    executable location = /usr/bin/ansible
    python version = 3.8.5 (default, Jan 27 2021, 15:41:15) [GCC 9.3.0]
  </code></pre>
  <p>My vars/default.yml</p>
  <pre><code>---
  create_user: sammy
  copy_local_key: &quot;{{ lookup('file', lookup('env','HOME') + '/.ssh/id_rsa.pub') }}&quot;
  sys_packages: [&quot;curl&quot;, &quot;vim&quot;, &quot;git&quot;, &quot;ufw&quot;]
  
  </code></pre>
  <p>What can I do to make this work?</p>
  <h2>UPdate</h2>
  <p>Tried this and failed</p>
  <pre><code>- name: Execute rsync command so the new user has the same authorized keys as root user
        ansible.builtin.shell:
          cmd: rsync --archive --chown\=={{ create_user }}:{{ create_user }} ~/.ssh /home/{{ create_user }}
  </code></pre>
  <p>error message is</p>
  <pre><code>
  TASK [Execute rsync command so the new user has the same authorized keys as root user] ***
  fatal: [server1]: FAILED! =&gt; {&quot;changed&quot;: false, &quot;msg&quot;: &quot;Unsupported parameters for (command) module: cmd Supported parameters include: _raw_params, _uses_shell, argv, chdir, creates, executable, removes, stdin, stdin_add_newline, strip_empty_ends, warn&quot;}
  
  PLAY RECAP *********************************************************************
  server1                    : ok=5    changed=4    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0
  </code></pre>