Thank you Kai,

That worked. I'm obviously new to Ansible so I'm sure I'll have many more 
questions in the future.

-Tim


On Thursday, November 2, 2017 at 11:44:14 AM UTC-4, Kai Stian Olstad wrote:
>
> 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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/a79dc049-8c6c-4333-9fc3-ad625ce125ee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to