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

**URL:** <https://forum.ansible.com/t/how-to-copy-file1-from-server-a-to-server-b-then-copy-file2-from-server-c-to-d-in-ansible/19823>\
**Category:** Ansible Project\
**Created:** [November 20, 2015, 11:25pm UTC](https://forum.ansible.com/t/how-to-copy-file1-from-server-a-to-server-b-then-copy-file2-from-server-c-to-d-in-ansible/19823 "2015-11-20T23:25:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bhotu](https://avatars.discourse-cdn.com/v4/letter/b/439d5e/32.png) [@Bhotu](https://forum.ansible.com/u/Bhotu)\
**Post date:** [November 20, 2015, 11:25pm UTC](https://forum.ansible.com/t/how-to-copy-file1-from-server-a-to-server-b-then-copy-file2-from-server-c-to-d-in-ansible/19823/1 "2015-11-20T23:25:16Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![Larry\_Fast](https://avatars.discourse-cdn.com/v4/letter/l/b3f665/32.png) [@Larry\_Fast](https://forum.ansible.com/u/Larry_Fast)\
**Post date:** [November 21, 2015, 7:11pm UTC](https://forum.ansible.com/t/how-to-copy-file1-from-server-a-to-server-b-then-copy-file2-from-server-c-to-d-in-ansible/19823/2 "2015-11-21T19:11:48Z")

</div>

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.
