# iterate with\_file contents ?

**URL:** <https://forum.ansible.com/t/iterate-with-file-contents/29208>\
**Category:** Ansible Project\
**Created:** [December 6, 2018, 7:12am UTC](https://forum.ansible.com/t/iterate-with-file-contents/29208 "2018-12-06T07:12:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicolas\_G](https://avatars.discourse-cdn.com/v4/letter/n/a183cd/32.png) [@Nicolas\_G](https://forum.ansible.com/u/Nicolas_G)\
**Post date:** [December 6, 2018, 7:12am UTC](https://forum.ansible.com/t/iterate-with-file-contents/29208/1 "2018-12-06T07:12:30Z")

</div>

I have some files under my role path dir :

`  
ls roles/my-role/files/  
file1 file2 file3

`

I can display the content of the file by running :  
`

- name: display contents

debug:  
msg: “{{ item }}”  
with\_file:

- “roles/my-role/files/file1”  
`

if in the last line I try something like :  
`with\_file:

- “roles/my-role/files/\*”

`

I get an error :

`fatal: [localhost]: FAILED! => {"msg": "could not locate file in lookup: roles/my-role/files/*"}`

Is there a way I can iterate inside the files directory and get the content ?

PS: I need the files content and note a list of the file names.

---

<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, 8:59am UTC](https://forum.ansible.com/t/iterate-with-file-contents/29208/2 "2018-12-06T08:59:49Z")

</div>

You need to use the fileglob, so something like this

- debug: msg="{{ lookup('file', item) }}"  
&nbsp;&nbsp;&nbsp;with\_fileglob: roles/my-role/files/\*

---

<div class="post-metadata">

**Author:** ![Nicolas\_G](https://avatars.discourse-cdn.com/v4/letter/n/a183cd/32.png) [@Nicolas\_G](https://forum.ansible.com/u/Nicolas_G)\
**Post date:** [December 6, 2018, 3:54pm UTC](https://forum.ansible.com/t/iterate-with-file-contents/29208/3 "2018-12-06T15:54:59Z")

</div>

worked like a charm , thank you so much Kai Stian !
