# Iterating with fileglob?

**URL:** <https://forum.ansible.com/t/iterating-with-fileglob/29207>\
**Category:** Ansible Project\
**Created:** [December 6, 2018, 6:17am UTC](https://forum.ansible.com/t/iterating-with-fileglob/29207 "2018-12-06T06:17:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bob](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bob/32/9260_2.png) [@bob](https://forum.ansible.com/u/bob)\
**Post date:** [December 6, 2018, 6:17am UTC](https://forum.ansible.com/t/iterating-with-fileglob/29207/1 "2018-12-06T06:17:06Z")

</div>

Is there a way to iterate the fileglob with a list?

If I have 3 groups

“group1”, “group2”, “group3”

and each group is represented as a directory on the management host

/path/to/group1

/path/to/group2

/path/to/group3

and I want to look into each of those paths for \*.cfg files

/path/to/group1/1.cfg  
/path/to/group2/2.cfg  
/path/to/group2/2\_1.cfg  
/path/to/group3/3.cfg

/path/to/group3/3\_1.cfg

/path/to/group3/3\_2.cfg

The way I understand the with\_fileglob won’t work?

Example

`

- name: my template  
template:  
src: “{{ item }}”  
dest: “/tmp//{{ item | basename }}”  
owner: root  
group: root  
mode: “0644”  
with\_fileglob:
- “{{ what\_goes\_here }}/\*.cfg”  
`

If the groups are dynamic and different for each host I cannot hard code the with\_fileglob. I need to be able to replace the list to with\_fileglob with /path/to/group1 and /path/to/group2 and /path/to/group3

---

<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:** [December 6, 2018, 2:11pm UTC](https://forum.ansible.com/t/iterating-with-fileglob/29207/2 "2018-12-06T14:11:12Z")

</div>

The easiest is to create a variable like config\_path, and set that to different value for each group.  
Then you can use that variable one in the with\_fileglob.
