On 02. nov. 2017 14:44, Tim Davidson wrote:
> Hello,
> 
> I'm trying to read some .csv files, then create config files for each of
> the .csv files, based on a template. Reading the files is not a problem.
> However, I can't seem to get the destination parameter to work. I would
> like the output file to be the name of the original .csv file with a .xml
> extension.
> 
> ---
> 
> - name: Read the csv files
>    find:
>      paths: /home/sysadmin/TimsTest1/roles/opengear/files
>      patterns: '*.csv'
>    register: files_matched
> 
> - name: Create OpenGear device configs
>    template:
>      src: "opengear8port.j2"
>      dest: "{{ files_matched.files.path | basename |
> regex_replace('csv','xml') }}"
>    with_items: "{{ files_matched.files }}"


When you're using with_items, it takes the first item in files_matched.files 
and put it in the variable called item, so your dest should be

  dest: "{{ item.path | basename | regex_replace('csv','xml') }}"


Regex_replace will overwrite csv in the filename too, to avoid that you can use 
this instead:

  dest: "{{ (item.path | basename).rsplit('.', 1)[0] }}.csv"


-- 
Kai Stian Olstad

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/095f51c1-e5b0-5ded-66c3-8a07dc470b02%40olstad.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to