# Copying file from remote host to another remote host

**URL:** <https://forum.ansible.com/t/copying-file-from-remote-host-to-another-remote-host/20853>\
**Category:** Ansible Project\
**Created:** [March 13, 2016, 4:41pm UTC](https://forum.ansible.com/t/copying-file-from-remote-host-to-another-remote-host/20853 "2016-03-13T16:41:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Danishka\_Navin](https://avatars.discourse-cdn.com/v4/letter/d/c0e974/32.png) [@Danishka\_Navin](https://forum.ansible.com/u/Danishka_Navin)\
**Post date:** [March 13, 2016, 4:41pm UTC](https://forum.ansible.com/t/copying-file-from-remote-host-to-another-remote-host/20853/1 "2016-03-13T16:41:22Z")

</div>

Hi,

I am new to Ansible, and I use Ansible 2.0.1.0 on CentOS 6.x.  
I need to copy a file from ServerA to Serverb (both are remote systems). I used following code block.  
Ansible host, ServerA, ServerB has same private key /root/.ssh/mykey.pem.  
each /root/myfile.txt file has just one line.

- name: Write to myfile.txt in host  
synchronize: mode=pull src=/root/myfile.txt dest=/root/myfile.txt  
delegate\_to: serverb  
register: file\_copied

In my inventory file I have following entries as well.  
[servera]  
**\<ServerA\_IP\>** ansible\_ssh\_private\_key\_file=/root/.ssh/mykey.pem

[serverb]  
**\<ServerB\_IP\>** ansible\_ssh\_private\_key\_file=/root/.ssh/mykey.pem

When I run the playbook I get following error.

fatal: [**\<ServerA\_IP\>** → **\<ServerB\_IP\>**]: FAILED! =\> {“changed”: false, “cmd”: “/usr/bin/rsync --delay-updates -F --compress --archive --rsh ‘/usr/bin/ssh -i /root/.ssh/ap-southeast-1-20130927.pem -S none -o StrictHostKeyChecking=no’ --out-format=‘\<\>%i %n%L’ " **\<ServerA\_IP\>** :/root/read.txt" "/root/read.txt"”, “failed”: true, “invocation”: {“module\_args”: {“\_local\_rsync\_path”: “rsync”, “\_substitute\_controller”: false, “archive”: true, “checksum”: false, “compress”: true, “copy\_links”: null, “delete”: false, “dest”: “/root/read.txt”, “dest\_port”: 22, “dirs”: false, “existing\_only”: false, “group”: null, “links”: null, “mode”: “pull”, “owner”: null, “partial”: false, “perms”: null, “private\_key”: “/root/.ssh/mykey.pem”, “recursive”: null, “rsync\_opts”: null, “rsync\_path”: null, “rsync\_timeout”: 0, “set\_remote\_user”: true, “src”: “ **\<ServerA\_IP\>** :/root/read.txt”, “ssh\_args”: null, “times”: null, “verify\_host”: false}}, “msg”: “Warning: Identity file /root/.ssh/mykey.pem not accessible: No such file or directory.\nPermission denied (publickey,gssapi-keyex,gssapi-with-mic).\r\nrsync: connection unexpectedly closed (0 bytes received so far) [receiver]\nrsync error: error in rsync protocol data stream (code 12) at io.c(600) [receiver=3.0.6]\n”, “rc”: 12}

1. How can I send a file from ServerA to ServerB?
2. How to append content of /root/myfile.txt file in ServerA to /root/myfile.txt file of Server B

Thanks,  
Danishka
