Using win_copy to copy 1 file to multiple directories.

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

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