i'm trying to run a task which deletes all the content of my project fiolder , without deleting the folder itself:
my folder : appFolder ----contains----> file1 , file2 ... fileN , directory1 ...directoryN
i ve tried to use ls , fileGlob , but that didn't work properly.
- name: delete old version files
file:
path: "{{ paths }}"
state: absent
with_filesglob:
- "{{paths}}deletes/*"
also with shell module (not good because it didn't delete file with special characters names)
- shell: ls -1 /some/dir
register: contents
- file: path=/some/dir/{{ item }} state=absent
with_items: {{ contents.stdout_lines }}
A better solution ?
Until #18910 is fixed (state=empty for dirs), we are stuck with workarounds.
Here's one of them:
- name: Clean build folder
shell: cd /project/build && find -mindepth 1 -maxdepth 1 -print0 | xargs -0 rm -rf --
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With