On 01.11.2018 05:46, Michael Mullay wrote:
You probably want to use
https://docs.ansible.com/ansible/latest/plugins/lookup/fileglob.html?highlight=with_fileglob


So without testing it, it would look something like (run in 'test mode'
(-C) first!):

- hosts: all
  tasks:
    - name: remove web dir contents
      file:
        path: "{{ item }}"
        state: absent
    with_fileglob:
      - "/tmp/xyz/*"

lookup plugins only work on Ansible controller aka localhost, not on remote hosts.


On Wed, Oct 31, 2018 at 8:50 PM <[email protected]> wrote:

Hi,

I am trying to delete all files under a specific directory (xyz) but it is
deleting the whole directory. Could someone please help.

---
- hosts: all
  tasks:
    - name: remove web dir contents
      file:
        path: '/tmp/xyz/'
        state: absent


Just recreate the directory in the next task, it that is not an option just use commad or shell module and run a command to do it.


--
Kai Stian Olstad

--
You received this message because you are subscribed to the Google Groups "Ansible 
Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/7d7a22de578d40824ff6e260afbfc807%40olstad.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to