Using with_fileglob is not behaving how I expect it to, am I missing something?

I’m attempting to use the file module to delete some cruft left over after installing Wordpress and I’m getting a not found warning when the task executes. Not sure what I’m doing wrong…

On the target host, the path and files exist:

$ ls /var/www/wordpress
$ backwpup_30357501_measurabl-plugins.2017-09-03.txt backwpup_30357501_wordpress.sql license.txt …

Task:

  • name: Ensure old backup files do not exist
    file:
    path: “{{ item }}”
    state: absent
    with_fileglob:
  • /var/www/wordpress/backwpup_*

Output when running task:
TASK [measurabl-wordpress : Ensure old backup files do not exist] **************
[WARNING]: Unable to find ‘/var/www/wordpress’ in expected paths.

with_fileglob runs on the ansible “controller” (localhost), not on the remote target.

If you want to list files or directories on a remote target, I recommend using the find module, registering the results, and then using a with_items over the results in a later task.

Ah, I see. Thanks for the clarification.