# task action over multiple files using fileglob query

**URL:** <https://forum.ansible.com/t/task-action-over-multiple-files-using-fileglob-query/13979>\
**Category:** Ansible Project\
**Created:** [November 22, 2013, 8:47pm UTC](https://forum.ansible.com/t/task-action-over-multiple-files-using-fileglob-query/13979 "2013-11-22T20:47:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Walid](https://avatars.discourse-cdn.com/v4/letter/w/ea5d25/32.png) [@Walid](https://forum.ansible.com/u/Walid)\
**Post date:** [November 22, 2013, 8:47pm UTC](https://forum.ansible.com/t/task-action-over-multiple-files-using-fileglob-query/13979/1 "2013-11-22T20:47:41Z")

</div>

Hi,  
I would like to run the module lineinfile against several files that exist on the remote managed host. I saw in the changelog for 1.4 that i can use the following lookup plugin feature:  
" added a fileglob filter that will return files matching a glob pattern. with\_items: “/foo/pattern/\*.txt | fileglob”

however i did not seem to get it right, see below, could you please let me know what other possible ways to do this, or what i might be doing wrong below  
I tried it with a simple debug task as follows:

- action: shell echo “{{ item }}”  
with\_items:
- " /etc/\* | fileglob"  
register: task  
tags:
- globtest
- debug: msg=“{{item.item}}”  
with\_items: task.results  
when: item.changed == True  
tags:
- globtest

however it did not work for me as i expected it, it returned the following :

TASK: [common | shell echo “”] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
changed: [tlcav117] =\> (item= /etc/\* | fileglob)

TASK: [common | debug msg=“{{item.item}}”] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [tlcav117] =\> (item={‘item’: ’ /etc/\* | fileglob’, u’delta’: u’0:00:00.002148’, u’cmd’: u’echo " /etc/\* | fileglob" ‘, u’end’: u’2013-11-22 23:44:54.216654’, u’stderr’: u’‘, u’stdout’: u’ /etc/\* | fileglob’, ‘invocation’: {‘module\_name’: ‘shell’, ‘module\_args’: u’echo " /etc/\* | fileglob"‘}, u’changed’: True, u’rc’: 0, u’start’: u’2013-11-22 23:44:54.214506’}) =\> {  
“item”: {  
“changed”: true,  
“cmd”: “echo " /etc/\* | fileglob" “,  
“delta”: “0:00:00.002148”,  
“end”: “2013-11-22 23:44:54.216654”,  
“invocation”: {  
“module\_args”: “echo " /etc/\* | fileglob"”,  
“module\_name”: “shell”  
},  
“item”: " /etc/\* | fileglob”,  
“rc”: 0,  
“start”: “2013-11-22 23:44:54.214506”,  
“stderr”: “”,  
“stdout”: " /etc/\* | fileglob”  
},  
“msg”: " /etc/\* | fileglob"  
}

regards

Walid

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [November 22, 2013, 8:56pm UTC](https://forum.ansible.com/t/task-action-over-multiple-files-using-fileglob-query/13979/2 "2013-11-22T20:56:51Z")

</div>

[http://ansibleworks.com/docs/playbooks\_loops.html#looping-over-fileglobs](http://ansibleworks.com/docs/playbooks_loops.html#looping-over-fileglobs)

---

<div class="post-metadata">

**Author:** ![Walid](https://avatars.discourse-cdn.com/v4/letter/w/ea5d25/32.png) [@Walid](https://forum.ansible.com/u/Walid)\
**Post date:** [November 22, 2013, 9:05pm UTC](https://forum.ansible.com/t/task-action-over-multiple-files-using-fileglob-query/13979/3 "2013-11-22T21:05:38Z")

</div>

Hi Michael,

i tried with\_fileglob first, however it references or resolves files from the local machine running ansible-playbook, not the remote managed machine. what i am trying to do is to change remote configuration files using lineinfile module.

kind regards

Walid

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [November 22, 2013, 9:13pm UTC](https://forum.ansible.com/t/task-action-over-multiple-files-using-fileglob-query/13979/4 "2013-11-22T21:13:40Z")

</div>

Fileglob always runs locally, this is true.

You should probably run a command like “ls” remotely and register the result, and then iterate over the result.stdout\_lines variable.

---

<div class="post-metadata">

**Author:** ![Walid](https://avatars.discourse-cdn.com/v4/letter/w/ea5d25/32.png) [@Walid](https://forum.ansible.com/u/Walid)\
**Post date:** [November 22, 2013, 9:15pm UTC](https://forum.ansible.com/t/task-action-over-multiple-files-using-fileglob-query/13979/5 "2013-11-22T21:15:54Z")

</div>

Thanks Michael, will do that. what was the new lookup plugin :  
with\_items: “/foo/pattern/\*.txt | fileglob”?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [November 22, 2013, 9:34pm UTC](https://forum.ansible.com/t/task-action-over-multiple-files-using-fileglob-query/13979/6 "2013-11-22T21:34:01Z")

</div>

Nope, simpler, as in docs:

with\_fileglob:

- /splat/\*.txt

– Michael
