Ansible way to delete all files in a remote directory

I know I can easily do:
shell: rm -f /etc/whatever/*

or possibly via a register variable on
shell: ls -1 /etc/whatever/*
register: dircontents

I had assumed I would be able to do this in Ansible trivially without templating, but am not finding it straightforward

  • with_glob enumerates “local” files only
  • file: doesn’t take wildcards as far as I know

Is there something obvious I’m missing, or are the above the available implementation-patterns for this?

Just call shell.

Would the file module work with state=absent?

The file module targets a specific file (unless used with with_items)
It can target a directory (recursively with recurse=yes in 1.1), but then the directory gets removed

Just tried this and it can’t both use state=absent AND recurse=yes. Only way I could make this happen is drop down to “command”.