# Unable to wildcard a template destination parameter

**URL:** <https://forum.ansible.com/t/unable-to-wildcard-a-template-destination-parameter/25901>\
**Category:** Ansible Project\
**Created:** [November 2, 2017, 1:44pm UTC](https://forum.ansible.com/t/unable-to-wildcard-a-template-destination-parameter/25901 "2017-11-02T13:44:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim\_Davidson](https://avatars.discourse-cdn.com/v4/letter/t/858c86/32.png) [@Tim\_Davidson](https://forum.ansible.com/u/Tim_Davidson)\
**Post date:** [November 2, 2017, 1:44pm UTC](https://forum.ansible.com/t/unable-to-wildcard-a-template-destination-parameter/25901/1 "2017-11-02T13:44:48Z")

</div>

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 I run the playbook, I receive the following on the final task:

> TASK [opengear : Create OpenGear device configs] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> 
> task path: /home/sysadmin/TimsTest1/roles/opengear/tasks/main.yml:9
> 
> fatal: [localhost]: FAILED! =\> {
> 
> “failed”: true,
> 
> “msg”: “the field ‘args’ has an invalid value, which appears to include a variable that is undefined. The error was: ‘list object’ has no attribute ‘path’\n\nThe error appears to have been in ‘/home/sysadmin/TimsTest1/roles/opengear/tasks/main.yml’: line 9, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Create OpenGear device configs\n ^ here\n”
> 
> }

I can’t seem to get the syntax correct on the destination. Any help is appreciated.

Thank you

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [November 2, 2017, 3:43pm UTC](https://forum.ansible.com/t/unable-to-wildcard-a-template-destination-parameter/25901/2 "2017-11-02T15:43:54Z")

</div>

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

&nbsp;&nbsp;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:

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

---

<div class="post-metadata">

**Author:** ![Tim\_Davidson](https://avatars.discourse-cdn.com/v4/letter/t/858c86/32.png) [@Tim\_Davidson](https://forum.ansible.com/u/Tim_Davidson)\
**Post date:** [November 2, 2017, 4:53pm UTC](https://forum.ansible.com/t/unable-to-wildcard-a-template-destination-parameter/25901/3 "2017-11-02T16:53:09Z")

</div>

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
