Answers: <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>
  
Answers: CC BY-SA 4.0
Answers: 2019-12-22T10:30:14.880Z
Answers: 2019-12-22T10:30:14.880Z
Answers: noobmaster69
Body: <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>
  
Comments: CC BY-SA 4.0
Comments: 2019-12-01T15:13:50.400Z
Comments: 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"?
Comments: Bruce Becker
Comments: CC BY-SA 4.0
Comments: 2019-12-01T15:24:57.143Z
Comments: @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.
Comments: Kyu96
Tags: <ansible>
Title: Ansible can't recursively delete a directory
UserDisplayName: Kyu96
ThreadText: # 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**: @username_1 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
  
  ```
  
  
  ---
  
  