# Using win\_copy to copy 1 file to multiple directories.

**URL:** <https://forum.ansible.com/t/using-win-copy-to-copy-1-file-to-multiple-directories/27383>\
**Category:** Ansible Project\
**Created:** [April 26, 2018, 9:16am UTC](https://forum.ansible.com/t/using-win-copy-to-copy-1-file-to-multiple-directories/27383 "2018-04-26T09:16:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![phil.spares12](https://avatars.discourse-cdn.com/v4/letter/p/47e85d/32.png) [@phil.spares12](https://forum.ansible.com/u/phil.spares12)\
**Post date:** [April 26, 2018, 9:16am UTC](https://forum.ansible.com/t/using-win-copy-to-copy-1-file-to-multiple-directories/27383/1 "2018-04-26T09:16:03Z")

</div>

Hello,

I’ve been working on a script to provision IIS and a basic website (literally just a html page at the moment) When th escript runs it creates two sites, and the directory for the sites in inetpub/wwwroot/_foldername_

I’m using this snippet to copy over the index.html file but i can only get it to copy to the first directory.

`

- name: Copy index.html to site directory  
win\_copy:  
src: files/index.html  
dest: “{{ ansible\_iis\_root}}\{{ ansible\_site\_folder }}\index.html”  
`

Could someone explain how i could do this recursively?

Something along the lines of

`  
foreach (website in websites) {

win\_copy:  
src: files/index.html  
dest: “{{ ansible\_iis\_root}}\{{ ansible\_site\_folder }}\index.html”

}

`

I don’t expect it to work like that ^^, i think i could do something using the loops and with\_items but the documentation has fried me. The end goal is when i run the playbook i specify how many sites to provision and as a base it just copies the html file to each one. Can this be done?

Thank you!

Phil

PS: The google groups text e

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [April 26, 2018, 9:29am UTC](https://forum.ansible.com/t/using-win-copy-to-copy-1-file-to-multiple-directories/27383/2 "2018-04-26T09:29:29Z")

</div>

Hi

You probably want to use with\_items here and the syntax would look something like

`

- win\_copy:  
src: files/index.html  
dest: ‘{{ ansible\_iis\_root }}{{ item }}\index.html’  
with\_items:
- site 1
- site 2

`

What this means is that the win\_copy task will copy the file in files/index.html to 2 different locations, e.g. if we consider ansible\_iis\_root to be C:\wwwroot then the above task will copy it to

- C:\wwwroot\site 1\index.html
- C:\wwwroot\site 2\index.html

What that syntax means is that it will run that task for each item/string that you define and substitute the variable {{ item }} with the current loop value. You can define the list beforehand as a variable and set **with\_items: ‘{{ iis\_sites }}’** if you want to drive it through config.

One thing to note, I would avoid using double quote when setting Windows paths, if you don’t use quotes or just a single quote, you don’t need to escape the backslashes which is easier to write.

Thanks

Jordan
