# How to copy file between two ansible clients

**URL:** <https://forum.ansible.com/t/how-to-copy-file-between-two-ansible-clients/13842>\
**Category:** Ansible Project\
**Created:** [November 5, 2013, 3:37am UTC](https://forum.ansible.com/t/how-to-copy-file-between-two-ansible-clients/13842 "2013-11-05T03:37:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![miukal](https://avatars.discourse-cdn.com/v4/letter/m/d6d6ee/32.png) [@miukal](https://forum.ansible.com/u/miukal)\
**Post date:** [November 5, 2013, 3:37am UTC](https://forum.ansible.com/t/how-to-copy-file-between-two-ansible-clients/13842/1 "2013-11-05T03:37:18Z")

</div>

Currently ansible control machine: A  
Currently ansible working host: B  
Another host in inventory: C  
I want to copy a file from C to B

At first, I tried rsync without ssh.

I create a rsync daemon in C and try to add this in the host B ansible tasks:

- name: copy file  
command: rsync -az [user@hostC.com](mailto:user@hostC.com)::module/TheFile /home/userinhostB

When ansible run this task, it hangs without the prompt “password”

But I can input this same command in the host B terminal and got the prompt “password”, and the file copy success.  
$ rsync -az [user@hostC.com](mailto:user@hostC.com)::module/TheFile /home/userinhostB

Then I tried to use rsync over ssh, like this

- name: copy file  
command: rsync -az -rsh “ssh” [userinhostC@hostC.com](mailto:userinhostC@hostC.com):DirToTheFile/TheFile /home/userinhostB

Still hanging.

Can anyone tell me where did I do this wrong?  
Or what should I do to copy the file.

---

<div class="post-metadata">

**Author:** ![Josh\_Whittaker](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@Josh\_Whittaker](https://forum.ansible.com/u/Josh_Whittaker)\
**Post date:** [November 5, 2013, 1:39pm UTC](https://forum.ansible.com/t/how-to-copy-file-between-two-ansible-clients/13842/2 "2013-11-05T13:39:21Z")

</div>

Isn’t rsh a long opt? --rsh=ssh

_-e, --rsh=COMMAND specify the remote shell to use_

Try this:

command: rsync -avz -e ssh [user@hostC.com](mailto:user@hostC.com):/module/TheFile /home/userinhostB

Using -v with rsync will at least let us know how far rsync actually gets in the execution, if at all.

Increase the verbosity on your ansible execution as well with -vvv

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [November 6, 2013, 1:53pm UTC](https://forum.ansible.com/t/how-to-copy-file-between-two-ansible-clients/13842/3 "2013-11-06T13:53:55Z")

</div>

rsync is naturally going to ask for passwords unless you are forwarding SSH credentials.

You could consider a combination of fetch + copy.

I also recommend SSH agent for local rsyncs.
