# Ansible copy respective file with {{ item }}

**URL:** <https://forum.ansible.com/t/ansible-copy-respective-file-with-item/17087>\
**Category:** Ansible Project\
**Created:** [December 17, 2014, 8:18am UTC](https://forum.ansible.com/t/ansible-copy-respective-file-with-item/17087 "2014-12-17T08:18:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fazal-e-Rehman\_Khan](https://avatars.discourse-cdn.com/v4/letter/f/9de053/32.png) [@Fazal-e-Rehman\_Khan](https://forum.ansible.com/u/Fazal-e-Rehman_Khan)\
**Post date:** [December 17, 2014, 8:18am UTC](https://forum.ansible.com/t/ansible-copy-respective-file-with-item/17087/1 "2014-12-17T08:18:22Z")

</div>

I have a yml file for variables which goes like this.

```auto
- newHosts     
   - hostIP: 192.168.1.22
     filename: file1 
   - hostIP: 192.168.1.23   
     filename: file2   

```

I am using add\_host: {{ item.hostIP }} with\_items {{ newHosts }} to add hosts on the runtime.

I want to copy respective file to respective hosts with something like {{ item.filename }} but it copies all files to each host. How I just copy only the corresponding file to the node. How can I do that?

Sorry Im a noob. But need an urgent help.

Thanks

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [December 17, 2014, 1:49pm UTC](https://forum.ansible.com/t/ansible-copy-respective-file-with-item/17087/2 "2014-12-17T13:49:10Z")

</div>

add\_host allows you to add per host facts

- add\_host: name={{ item.hostIP }} copyfile={{ item.filename }}

- copy: src={{copyfile}} ...

---

<div class="post-metadata">

**Author:** ![Fazal-e-Rehman\_Khan](https://avatars.discourse-cdn.com/v4/letter/f/9de053/32.png) [@Fazal-e-Rehman\_Khan](https://forum.ansible.com/u/Fazal-e-Rehman_Khan)\
**Post date:** [December 18, 2014, 2:40pm UTC](https://forum.ansible.com/t/ansible-copy-respective-file-with-item/17087/3 "2014-12-18T14:40:11Z")

</div>

Thanks a lot Brian. It worked. 🙂
