# file module: absent recurse=yes and Directory not empty

**URL:** <https://forum.ansible.com/t/file-module-absent-recurse-yes-and-directory-not-empty/14938>\
**Category:** Ansible Project\
**Created:** [April 4, 2014, 1:48pm UTC](https://forum.ansible.com/t/file-module-absent-recurse-yes-and-directory-not-empty/14938 "2014-04-04T13:48:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maxim\_Odinintsev](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@Maxim\_Odinintsev](https://forum.ansible.com/u/Maxim_Odinintsev)\
**Post date:** [April 4, 2014, 1:48pm UTC](https://forum.ansible.com/t/file-module-absent-recurse-yes-and-directory-not-empty/14938/1 "2014-04-04T13:48:33Z")

</div>

Hello,

When I’m run this job, but on some hosts return output:  
rmtree failed: [Errno 39] Directory not empty: ‘/home/master/www/static.master/images/posters’

Sure this directories is not empty, and I’m want remove it recursive. But why i can’t do this with file module ?

`

- name: Cleaner  
hosts: all  
sudo: yes

tasks:

- name: get cache dirs  
shell: ls -1 /var/lib/nginx/cache/  
register: cache

- name: Remove cache  
file: name=/var/lib/nginx/cache/{{ item }} state=absent recurse=yes  
with\_items: cache.stdout\_lines

- name: get static dirs  
shell: ls -1 /home/master/www/static.master/  
register: static

- name: Clean static  
file: name=/home/master/www/static.master/{{ item }} state=absent recurse=yes  
with\_items: static.stdout\_lines

`

Thank you

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [April 4, 2014, 3:24pm UTC](https://forum.ansible.com/t/file-module-absent-recurse-yes-and-directory-not-empty/14938/2 "2014-04-04T15:24:00Z")

</div>

Sounds like a good feature request or pull request addition – can you file a ticket on [github.com/ansible/ansible](http://github.com/ansible/ansible) ?

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [April 4, 2014, 4:29pm UTC](https://forum.ansible.com/t/file-module-absent-recurse-yes-and-directory-not-empty/14938/3 "2014-04-04T16:29:34Z")

</div>

I will mention that we use ‘file’ to recursively delete a directory, but it does require ‘force=yes’

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [April 4, 2014, 6:11pm UTC](https://forum.ansible.com/t/file-module-absent-recurse-yes-and-directory-not-empty/14938/4 "2014-04-04T18:11:55Z")

</div>

Perhaps the force is causing extra checking?

If so, maybe it can be removed.

---

<div class="post-metadata">

**Author:** ![santosh\_verma](https://avatars.discourse-cdn.com/v4/letter/s/22d042/32.png) [@santosh\_verma](https://forum.ansible.com/u/santosh_verma)\
**Post date:** [November 23, 2016, 12:22pm UTC](https://forum.ansible.com/t/file-module-absent-recurse-yes-and-directory-not-empty/14938/5 "2016-11-23T12:22:15Z")

</div>

Still same error:  
msg: rmtree failed: [Errno 39] Directory not empty

- name: Removing jenkins folder  
file: path={{ base\_dir }}/tomcat7/webapps/jenkins state=absent force=yes

---

<div class="post-metadata">

**Author:** ![Diego\_Villacis](https://avatars.discourse-cdn.com/v4/letter/d/898d66/32.png) [@Diego\_Villacis](https://forum.ansible.com/u/Diego_Villacis)\
**Post date:** [March 7, 2017, 2:24pm UTC](https://forum.ansible.com/t/file-module-absent-recurse-yes-and-directory-not-empty/14938/6 "2017-03-07T14:24:40Z")

</div>

Getting the same error, does anyone know if there is any update on this?
