First thing that comes to mind is removing the folder from the
FilesOver30.files list, for instance using 'difference':
https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#selecting-from-sets-or-lists-set-theory

On Wed, 12 May 2021 at 18:49, Jeremy Smith <[email protected]> wrote:
>
> For reference, the unc_path variable seen above is the path to the 
> diagnostics folder.
>
> On Wednesday, May 12, 2021 at 9:48:45 AM UTC-7 Jeremy Smith wrote:
>>
>> Hello All,
>>
>> Background: We have a "diagnostics" folder on our network that is used to 
>> store logs exported from our flagship application.
>>
>> The problem I'm trying to solve is to remove any files/folders older than 30 
>> days from the "diagnostics" folder.
>>
>> The following code is being used to perform this:
>> - name: Find all files older than 30 days in diagnostics folder
>>     win_find:
>>         paths: "{{ unc_path }}"
>>         file_type: directory
>>         age: 30d
>>         #recurse: yes
>>     register: FilesOver30
>>
>>   - name: Delete all files/folders older than 30 days from diagnostics folder
>>     win_file:
>>       path: "{{ unc_path }}"
>>       state: absent
>>     with_items: "{{ FilesOver30.files }}"
>>
>> The issue I'm having is, if there are no files newer than 30 days in the 
>> "diagnostics" folder, it actually nukes the diagnostics folder itself, which 
>> is not the intended result.
>>
>> Need to be able to have it remove any files/folders older than 30 days from 
>> this folder witout nuking the entire thing.
>>
>> Thanks in advance for the feedback!
>
> --
> 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/8a2f9dc4-5c99-459c-89a2-20bc488a4c0fn%40googlegroups.com.



-- 
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

-- 
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/CAL8fbwPjo%2Bc5ZpmtE1gbrhqTuhTKXOnm0d%2BOvZPxLyJvtRHGpA%40mail.gmail.com.

Reply via email to