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

39 views
Skip to first unread message

vowner

unread,
Nov 28, 2018, 3:35:37 AM11/28/18
to Ansible Project
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.

---

- name: copy the certificates to the IHS server
  hosts
: A1
  tasks
:
   
- name: Transfer file from JTS to IHS
      synchronize
:
        src
: /opt/IBM/myapp/security/file2.crt
        dest
: /opt/security directory
        mode
: pull
      delegate_to
: IHSEnter code here...


rpa...@pluribusnetworks.com

unread,
Nov 28, 2018, 4:22:06 AM11/28/18
to Ansible Project
I think you can use fetch option which is available in Ansible.

Indian Velumani

unread,
Nov 28, 2018, 6:41:33 AM11/28/18
to ansible...@googlegroups.com
Hi,

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

---

- name: copy the certificates to the IHS server
  hosts
:  servers  

  tasks
:
    
- name: Transfer file from JTS to IHS
      synchronize
:
        src
: /opt/IBM/myapp/security/file2.crt
        dest
: /opt/security directory
        mode
: pull
      delegate_to
: IHSEnter code here...  
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/c0043f82-2757-4d4f-a038-f50dedac03a1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Regards,
Indian Velumani

vowner

unread,
Nov 28, 2018, 10:45:27 AM11/28/18
to Ansible Project
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


Sanjay Thakur

unread,
Nov 28, 2018, 3:41:55 PM11/28/18
to Ansible Project
Since, you are using delegate_to: <IHS server> 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. 


On Wednesday, November 28, 2018 at 2:05:37 PM UTC+5:30, vowner wrote:
Reply all
Reply to author
Forward
0 new messages