Errativ behavior when looping over a fileglob

Hi,

I am trying to remove a bunch of files wiht the following code:

$ cat site.yml

with_fileglob is a lookup plugin, and lookup plugin runs on the Ansible controller and not the remote host.

To do what what you want to do, you must use the find module to find the files and register the output in a variable.
Then you can delete them with the file module and with_items.

Hi Kai,

thanks for the nudge. I was able to solve the issue.

> - name: remove extra files that may be on the systems
> file:
> path: "{{ item }}"
> state: absent
> with_fileglob:
> - "/etc/apt/sources.list.d/zda-*.list"
> - "/etc/apt/sources.list.d/exp-mc.list"
> - "/etc/apt/sources.list.d/sid-mc.list"
> - "/etc/apt/sources.list.d/sid-zg-stable-mc.list"
> - "/etc/apt/sources.list.d/sid-zg-unstable-mc.list"
> - "/etc/apt/sources.list.d/stretch-mc.list"
> - "/etc/apt/sources.list.d/stretch-security.list"
> - "/etc/apt/sources.list.d/stretch-zg-stable-mc.list"
> - "/etc/apt/sources.list.d/stretch-zg-unstable-mc.list"
> - "/etc/apt/sources.list.d/buster-mc.list"
> - "/etc/apt/sources.list.d/stretch-zg-stable-mc.list"
> - "/etc/apt/sources.list.d/stretch-security.list"
> - "/etc/apt/preferences.d/??-zda-*.pref"
> - "/etc/apt/preferences.d/10-sid-zg-unstable-mc.pref"
> - "/etc/apt/preferences.d/20-sid-zg-stable-mc.pref"
> - "/etc/apt/preferences.d/50-sid-security.pref"
> - "/etc/apt/preferences.d/70-sid.pref"
> - "/etc/apt/preferences.d/99-default.pref"

with_fileglob is a lookup plugin, and lookup plugin runs on the Ansible controller and not the remote host.

Ouch. That was not clear to me at all, but of course it explains
eveything. So you use with_fileglob mainly when you transport files from
the controller to the remote.

To do what what you want to do, you must use the find module to find the files and register the output in a variable.
Then you can delete them with the file module and with_items.

This is my code: