Hi @cndpansible, after poking around with this a little, think I was able to make it behave the way you’re asking for by adding file_type: any to the ansible.builtin.find block as per the module documentation.
During my initial testing, and confirmed by my reading of that page, ansible.builtin.find defaults to finding files. That, combined with recurse: true was finding files at all levels, but not the directories.
I think that explains why it was behaving that way.
Doing it the ansible way will work, but if your folder contains many items then it will get slow very quickly. In practice for me this only worked OK up to a few hundred files.
For anything more I used ansible.builtin.command and rm -rf…
Indeed, Ansible does not delete directories, but it empties them fine.
This is perfectly OK to me, I will work to understand the solutions but might stick to the original syntax.
Thanks as well for the warning about timing. I tested and indeed, emptying ~/.cache (even if not that big) takes a long time
I did a little more digging, and if what you’re really after is “delete everything from this directory” without taking a huge performance hit like like @dnmvisser mentioned, you can simply add file_type: any and remove recurse (and keep hidden: true). This will return all files, and all top level directories.
And ansible.builtin.file will delete a directory and its content with state: absent
Great, I understand, covering all “file types” will include directories, and removing them at top level (no recursion needed) won’t impact performance, correct?