<p>You may find the following format to be helpful:</p>

<pre><code>- name: Recursively change ownership of a directory  
file:  
  path: /etc/foo
  state: directory
  recurse: yes
  owner: foo
  group: foo
</code></pre>

CC BY-SA 4.0
2019-12-22T10:30:14.880Z
2019-12-22T10:30:14.880Z
noobmaster69
<p>So, I am trying to recursively delete a directory with all files/folders inside.
I tried:</p>

<pre><code>  - name: Cleaning up
    file:
      state: absent
      path: /tmp/myfolder/
</code></pre>

<p>But the directory did not get deleted. Is there any force/recursive parameter I can add? What am I missing?</p>

CC BY-SA 4.0
2019-12-01T15:13:50.400Z
I cannot reproduce this at all - were there any error messages? Are you sure you're targetting the correct host? Is the task "ok" or "changed"?
Bruce Becker
CC BY-SA 4.0
2019-12-01T15:24:57.143Z
@BruceBecker The task is changed. I did install files from this directory before, so maybe there is still some process in the background that is not completed that prevents deleting the directory? But I did not get any error prompt.
Kyu96
<ansible>
Ansible can't recursively delete a directory
Kyu96
# Ansible can't recursively delete a directory

(Asked by: username_0 on 2019-12-01)

So, I am trying to recursively delete a directory with all files/folders inside.
I tried:
  - name: Cleaning up
    file:
      state: absent
      path: /tmp/myfolder/

But the directory did not get deleted. Is there any force/recursive parameter I can add? What am I missing?

**Tags:** ansible

> **Comments:**
> **username_1**: I cannot reproduce this at all - were there any error messages? Are you sure you're targetting the correct host? Is the task "ok" or "changed"?  
> **username_0**: @BruceBecker The task is changed. I did install files from this directory before, so maybe there is still some process in the background that is not completed that prevents deleting the directory? But I did not get any error prompt.  

---

## 1 answers

### Answer by username_2 on 2019-12-22. Score: 1

You may find the following format to be helpful:
- name: Recursively change ownership of a directory  
file:  
  path: /etc/foo
  state: directory
  recurse: yes
  owner: foo
  group: foo


---

