# How to copy certain files in different servers (different location )to another remote server using ansible.

**URL:** <https://forum.ansible.com/t/how-to-copy-certain-files-in-different-servers-different-location-to-another-remote-server-using-ansible/29137>\
**Category:** Ansible Project\
**Created:** [November 28, 2018, 8:35am UTC](https://forum.ansible.com/t/how-to-copy-certain-files-in-different-servers-different-location-to-another-remote-server-using-ansible/29137 "2018-11-28T08:35:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vivek\_mv](https://avatars.discourse-cdn.com/v4/letter/v/d26b3c/32.png) [@vivek\_mv](https://forum.ansible.com/u/vivek_mv)\
**Post date:** [November 28, 2018, 8:35am UTC](https://forum.ansible.com/t/how-to-copy-certain-files-in-different-servers-different-location-to-another-remote-server-using-ansible/29137/1 "2018-11-28T08:35:37Z")

</div>

hello Experts,

How to copy certain files in different servers (different location )to another remote server using ansible.

for example i have 5 application servers (A1,A2, A3, A4, A5), from theser servers i need to copy 2 files (file1.xml and file2.jks)

location of file1.xml for all 5 application servers are (/opt/IBM/myapp/plugins/file1.xml)  
location of file2.jks for all 5 application servers are (/opt/IBM/myapp/security/file2.crt)

now i want to copy these 2 different files from all 5 application servers to my IHS servers 2 different location.

example: file1.xml of all 5 should got to IHS server’s /opt/plugin folder  
and file2.crt should go to IHS servers /opt/security directory.

I tried with some possible ways of playbook using delegate option but not getting succeded here.

`

---

<div class="post-metadata">

**Author:** ![rpachi](https://avatars.discourse-cdn.com/v4/letter/r/b5e925/32.png) [@rpachi](https://forum.ansible.com/u/rpachi)\
**Post date:** [November 28, 2018, 9:22am UTC](https://forum.ansible.com/t/how-to-copy-certain-files-in-different-servers-different-location-to-another-remote-server-using-ansible/29137/2 "2018-11-28T09:22:06Z")

</div>

I think you can use fetch option which is available in Ansible.

---

<div class="post-metadata">

**Author:** ![Indian\_Velumani](https://avatars.discourse-cdn.com/v4/letter/i/e99b99/32.png) [@Indian\_Velumani](https://forum.ansible.com/u/Indian_Velumani)\
**Post date:** [November 28, 2018, 11:41am UTC](https://forum.ansible.com/t/how-to-copy-certain-files-in-different-servers-different-location-to-another-remote-server-using-ansible/29137/3 "2018-11-28T11:41:10Z")

</div>

Hi,

Edit your hosts file like this  
/etc/Ansible/hosts  
[servers]  
A1  
A2  
A3  
A4  
A5  
then:

---

<div class="post-metadata">

**Author:** ![vivek\_mv](https://avatars.discourse-cdn.com/v4/letter/v/d26b3c/32.png) [@vivek\_mv](https://forum.ansible.com/u/vivek_mv)\
**Post date:** [November 28, 2018, 3:45pm UTC](https://forum.ansible.com/t/how-to-copy-certain-files-in-different-servers-different-location-to-another-remote-server-using-ansible/29137/4 "2018-11-28T15:45:27Z")

</div>

Hello Velumani,

I tried by your suggestion, but getting below error. but ssh is enabled to all target servers from controller machine but here its getting failed… not sure the exact reason.

`  
[root@vwjts good]# ansible-playbook copycerts3.yml

PLAY [copy the certificates to the IHS server] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [Gathering Facts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [10.170.3.12]

TASK [Transfer file from JTS to IHS] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [10.170.3.12]: UNREACHABLE! =\> {“changed”: false, “msg”: “Failed to connect to the host via ssh: ssh: Could not resolve hostname ihs: Name or service not known\r\n”, “unreachable”: true}  
to retry, use: --limit @/etc/ansible/roles/IBM2/tasks/good/copycerts3.retry

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
10.170.3.12 : ok=1 changed=0 unreachable=1 failed=0

`

---

<div class="post-metadata">

**Author:** ![Sanjay1](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@Sanjay1](https://forum.ansible.com/u/Sanjay1)\
**Post date:** [November 28, 2018, 8:41pm UTC](https://forum.ansible.com/t/how-to-copy-certain-files-in-different-servers-different-location-to-another-remote-server-using-ansible/29137/5 "2018-11-28T20:41:54Z")

</div>

Since, you are using **delegate\_to:** so, you should check SSH connection or DNS resolution from IHS server to all 5 different application servers to make sure you can connect to all app servers.
