How to Copy Files between two Remote Servers using Ansible

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

`

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.

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