How to Copy file1 from server A to server B; then Copy file2 from server C to D in Ansible ?

46 views
Skip to first unread message

Bhotu

unread,
Nov 20, 2015, 6:25:17 PM11/20/15
to Ansible Project

I want to copy files from one server to another using Ansible. Below is the example

Server A ------> Server B
Server C ------> Server D

I have my one file on Server A and specifically want to copy that file on to the server B, and same for server C to D. Folder to save files to the destination is the same. I can do it for 2 or 3 hosts. But how can I create dynamically for let us say 100 nodes to copy particular single file assign to desired server only. 


Larry Fast

unread,
Nov 21, 2015, 2:11:49 PM11/21/15
to Ansible Project
You should start with a data definition that is consumable by Ansible. I'm still not quite clear on what you want to do with 100 servers but I'll start by assuming "For each server, copy one file, unique to server X onto server Y. Destination path = source path."

In this example I would create an inventory like this:
[source_hosts]
host1  file_path=/etc/...  dest_host=another_hostname

With that data structure you could create a Task like
- hosts: source_hosts
  tasks:
   
- fetch: src={{src_path}} dest=/tmp/...
   
- delegate_to:"{{dest_host}}"
      copy
: src={{/tmp/...}} dest={{file_path}}

Caveat Emptor: I did not try running this. 
Reply all
Reply to author
Forward
0 new messages