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

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.

`

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

Hi,

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

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

`

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.