# Does the file module handle wildcards?

**URL:** <https://forum.ansible.com/t/does-the-file-module-handle-wildcards/18888>\
**Category:** Ansible Project\
**Created:** [July 29, 2015, 6:12pm UTC](https://forum.ansible.com/t/does-the-file-module-handle-wildcards/18888 "2015-07-29T18:12:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Will\_Dennis](https://avatars.discourse-cdn.com/v4/letter/w/919ad9/32.png) [@Will\_Dennis](https://forum.ansible.com/u/Will_Dennis)\
**Post date:** [July 29, 2015, 6:12pm UTC](https://forum.ansible.com/t/does-the-file-module-handle-wildcards/18888/1 "2015-07-29T18:12:35Z")

</div>

Hi all,

Trying to write a task that ensures no files matching a wildcard are present in a given directory (and if so, delete them.)

I’ve tried the following, both of which do not work:

`

- name: Ensure that any default ‘Wired connection’ entry is deleted  
file: path=/etc/NetworkManager/system-connections/Wired\* state=absent  
`

`

- name: Ensure that any default ‘Wired connection’ entry is deleted  
file: path=/etc/NetworkManager/system-connections/{{ item }} state=absent  
with\_fileglob: Wired\*  
`

The first does nothing (always reports ‘ok’), but the second appears to fail altogether, without an error:

`  
TASK: [laptop\_netcfg | Ensure there is an NM connection entry for DHCP LAN] \*\*\*  
ok: [dhcp-client]

TASK: [laptop\_netcfg | Ensure that any default ‘Wired connection’ entry is deleted] \*\*\*

PLAY [next\_play] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
skipping: no hosts matched  
`

Notice no task status code under the task… I take it “with\_fileglob” is deprecated or something? (picked it up off an old M.DeHaan post off this mailing list…)

Anyways, how would I go about doing something like this?

Thanks,  
Will

---

<div class="post-metadata">

**Author:** ![Craig\_Moynes](https://avatars.discourse-cdn.com/v4/letter/c/9fc29f/32.png) [@Craig\_Moynes](https://forum.ansible.com/u/Craig_Moynes)\
**Post date:** [July 29, 2015, 7:00pm UTC](https://forum.ansible.com/t/does-the-file-module-handle-wildcards/18888/2 "2015-07-29T19:00:05Z")

</div>

Could you use the find module to get the list of matching files? It is only available in v2.0, I have previously used the command module to execute a find on a remote system to get a list of files, then used the file module to check the state.

---

<div class="post-metadata">

**Author:** ![Will\_Dennis](https://avatars.discourse-cdn.com/v4/letter/w/919ad9/32.png) [@Will\_Dennis](https://forum.ansible.com/u/Will_Dennis)\
**Post date:** [July 30, 2015, 1:13am UTC](https://forum.ansible.com/t/does-the-file-module-handle-wildcards/18888/3 "2015-07-30T01:13:23Z")

</div>

Thanks for the tip, but not running 2.0 yet… No way to do this on 1.9?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [July 30, 2015, 1:17am UTC](https://forum.ansible.com/t/does-the-file-module-handle-wildcards/18888/4 "2015-07-30T01:17:36Z")

</div>

if no find module just use:  
shell: find ...

---

<div class="post-metadata">

**Author:** ![Craig\_Moynes](https://avatars.discourse-cdn.com/v4/letter/c/9fc29f/32.png) [@Craig\_Moynes](https://forum.ansible.com/u/Craig_Moynes)\
**Post date:** [July 30, 2015, 11:05am UTC](https://forum.ansible.com/t/does-the-file-module-handle-wildcards/18888/5 "2015-07-30T11:05:46Z")

</div>

Sorry if I wasn’t clear. I am running 1.9.2 and I use command module to execute a find on a remote system to get a list of files, then used the file module to check the state.

Is that clearer?
