title: Deleting files that matches a particular naming criteria in ansible
body: <p>In ansible i need to delete files from a folder that matches a specific naming criteria: like all files and folders that starts with abc</p>
  
  <p>Want to delete /abc*.*</p>
  
  <p>i have used below task to remove all files:</p>
  
  <pre><code> - name: Removes all files
     file:
       path: "&lt;folder path&gt;/root/"
       state: absent
  </code></pre>
  
  <p>However i need to be able to specify a criteria here somewhere to delete only those files and folders  with names that start with abc-*.</p>
  
  <p>I have already tried to use :</p>
  
  <pre><code>- name: Removes files that start with abc
    file:
       path: "{{item}}"
       state: absent
    with_fileglob:
       - &lt;path&gt;/abc*
  </code></pre>
  
  <p>But this is not matching any files/folders. </p>
  
  <p>I have also tried :</p>
  
  <pre><code> - name: Finds files and folders
       find:
          paths: "&lt;path&gt;/"
          patterns: "abc*"
          recurse: yes
       register: result
  
   - name: Removes  files and folders
     file:
       path: "{{item.path}}"
       state: absent
     with_items: '{{result.files}}' 
  </code></pre>
  
  <p>This as well doesnt return any files or folders.</p>