Hi Wei,

If you are referring to this code, then it is deleting the destination
folder too.

- hosts: all
  tasks:
  - name: Ansible delete files examples
    find:
      paths: /home/mdtutorials2/findmodule/examples
      patterns: "*.log"
      age: "100d"
      recurse: yes
      register: files_to_delete

  - name: Ansible delete file glob
    file:
      path: "{{ item.path }}"
      state: absent
    with_items: "{{ files_to_delete.files }}"

Best Regards,
Reneesh K


On Mon, Dec 28, 2020 at 9:20 PM Wei-Yen Tan <[email protected]> wrote:

> scroll to the bottom.. it has your  example:
>
> Using the Ansible find module to search for files/folder - My Daily
> Tutorials
> <https://www.mydailytutorials.com/using-ansible-find-module-search-filesfolder/>
>
> On Tue, 29 Dec 2020 at 16:15, Wei-Yen Tan <[email protected]> wrote:
>
>>
>> Use the find module to list the files you want /register the files and
>> then loop the car to remove the file in file module
>> On Tue, 29 Dec 2020 at 4:06 PM Reneesh K <[email protected]> wrote:
>>
>>> I used the file module, but it is deleting even the logs directory. This
>>> is my code.
>>>
>>> - name: empty logs directory
>>>   file:
>>>     path: /app/logs/
>>>     state: absent
>>>
>>> Best Regards,
>>> Reneesh K
>>>
>>>
>>> On Mon, Dec 28, 2020 at 9:02 PM Wei-Yen Tan <[email protected]>
>>> wrote:
>>>
>>>> Even better. Use file module
>>>>
>>>> On Tue, 29 Dec 2020 at 4:01 PM Tej Singh Rana <
>>>> [email protected]> wrote:
>>>>
>>>>> use command or shell module
>>>>>
>>>>>
>>>>> regards,
>>>>>
>>>>>
>>>>> On Tue, Dec 29, 2020 at 8:26 AM Reneesh K <[email protected]> wrote:
>>>>>
>>>>>> How do I delete all files under a directory?
>>>>>>
>>>>>> --
>>>>>> You received this message because you are subscribed to the Google
>>>>>> Groups "Ansible Project" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it,
>>>>>> send an email to [email protected].
>>>>>> To view this discussion on the web visit
>>>>>> https://groups.google.com/d/msgid/ansible-project/65531941-f099-417e-b5e6-3f26f0c96240n%40googlegroups.com
>>>>>> <https://groups.google.com/d/msgid/ansible-project/65531941-f099-417e-b5e6-3f26f0c96240n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>> .
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> *---------------------*
>>>>> *Tej Singh Rana*
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Ansible Project" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to [email protected].
>>>>> To view this discussion on the web visit
>>>>> https://groups.google.com/d/msgid/ansible-project/CADBoQTpaj8C9-vtQbfAFh4rGy-Y%3Duo%3DdqJZUr%3D70G-zKheMj-Q%40mail.gmail.com
>>>>> <https://groups.google.com/d/msgid/ansible-project/CADBoQTpaj8C9-vtQbfAFh4rGy-Y%3Duo%3DdqJZUr%3D70G-zKheMj-Q%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>>
>>>> --
>>>>
>>> You received this message because you are subscribed to a topic in the
>>>> Google Groups "Ansible Project" group.
>>>> To unsubscribe from this topic, visit
>>>> https://groups.google.com/d/topic/ansible-project/0LPtwD5c2Yw/unsubscribe
>>>> .
>>>> To unsubscribe from this group and all its topics, send an email to
>>>> [email protected].
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/ansible-project/CA%2BjXPxi0zOg0fdpYT4N4uRPjJVuazzX_m53gcY%2B-Rr1nyq_gTw%40mail.gmail.com
>>>> <https://groups.google.com/d/msgid/ansible-project/CA%2BjXPxi0zOg0fdpYT4N4uRPjJVuazzX_m53gcY%2B-Rr1nyq_gTw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Ansible Project" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/ansible-project/CAP4UftRgUy7KbJkemG_TOtAVS3otzBpAwdNRoB_ATe2B%2B0c-Sg%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/ansible-project/CAP4UftRgUy7KbJkemG_TOtAVS3otzBpAwdNRoB_ATe2B%2B0c-Sg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Ansible Project" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/ansible-project/0LPtwD5c2Yw/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CA%2BjXPxhuKLJuN6aySjNnf3FPRoz2DucGCw5xoP2kxKTdtpNF0A%40mail.gmail.com
> <https://groups.google.com/d/msgid/ansible-project/CA%2BjXPxhuKLJuN6aySjNnf3FPRoz2DucGCw5xoP2kxKTdtpNF0A%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAP4UftTAHUtZN3Fa3eg%2BCEz5HRQF7Qgp0LnW_QqmVfKhJBoG2A%40mail.gmail.com.

Reply via email to