# How to Copy Files between two Remote Servers using Ansible

**URL:** <https://forum.ansible.com/t/how-to-copy-files-between-two-remote-servers-using-ansible/28009>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [July 10, 2018, 3:19pm UTC](https://forum.ansible.com/t/how-to-copy-files-between-two-remote-servers-using-ansible/28009 "2018-07-10T15:19:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![abhinav.grntla](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@abhinav.grntla](https://forum.ansible.com/u/abhinav.grntla)\
**Post date:** [July 10, 2018, 3:19pm UTC](https://forum.ansible.com/t/how-to-copy-files-between-two-remote-servers-using-ansible/28009/1 "2018-07-10T15:19:06Z")

</div>

I am trying to copy the files from Server A to Server B with Ansible running in Server C.

I have tried using Ansible Synchronize Module:

Exchanged SSH id\_rsa.pub keys between the servers. Was able to ssh between the servers without asking password.

When running playbook it was able to gather\_facts but throwing error during task execution. If seen in verbose output it is trying yo connect to different ip’s rather than the ips mentioned in the host file.

Hosts file

`  
[ServerA] 192.168.1.7 ansible\_user=ubuntu  
[ServerB] 192.168.1.2 ansible\_user=ubuntu

`

main.yml

`

---

<div class="post-metadata">

**Author:** ![Daria\_Serkova](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@Daria\_Serkova](https://forum.ansible.com/u/Daria_Serkova)\
**Post date:** [July 11, 2018, 11:38am UTC](https://forum.ansible.com/t/how-to-copy-files-between-two-remote-servers-using-ansible/28009/2 "2018-07-11T11:38:58Z")

</div>

Hi Abhinav G,

It’s worth to look at rsyncd.conf, because ansible-synchronize is a wrapper over rsync and it could be different from ssh.  
Try to do rsync between the servers manually.

---

<div class="post-metadata">

**Author:** ![Sunil\_bansal](https://avatars.discourse-cdn.com/v4/letter/s/bbe5ce/32.png) [@Sunil\_bansal](https://forum.ansible.com/u/Sunil_bansal)\
**Post date:** [July 11, 2018, 2:55pm UTC](https://forum.ansible.com/t/how-to-copy-files-between-two-remote-servers-using-ansible/28009/3 "2018-07-11T14:55:36Z")

</div>

You require to have SSH entries i.e. keys of controller on both the nodes. This would resolve the error.  
And then use copy module to copy files.

Regards,  
Sunil
