I don’t think you can achieve what you want if the file keep generating. 
Ansible is not real time monitor/scanning. The most recently at the point of 
time when you trigger only. 

Thanks and Best Regards,

Thanh.

> On 23 Dec 2022, at 11:55, Nico Kadel-Garcia <nka...@gmail.com> wrote:
> 
> On Thu, Dec 1, 2022 at 7:10 PM Vladimir Botka <vbo...@gmail.com> wrote:
>> 
>> Use Ansible module *find* and sort the directories by *ctime*. For
>> example, given the tree
> 
> This is only reliable if nothing else writes anything else in that
> tree between the first command, tand the "tree" command.
> 
> 
>> shell> tree /tmp/test
>> /tmp/test
>> ├── 2022-12-01_1701
>> ├── 2022-12-01_1702
>> └── 2022-12-01_1703
>> 
>> Declare the variable
>> 
>>  last_dir: "{{ (out.files|sort(attribute='ctime')|last).path }}"
>> 
>> The tasks below
>> 
>>    - find:
>>        path: /tmp/test
>>        file_type: directory
>>      register: out
>>    - debug:
>>        var: last_dir
>> 
>> give
>> 
>>  last_dir: /tmp/test/2022-12-01_1703
>> 
>> If you want to take look at the *ctime*
>> 
>>  path_ctime: "{{ out.files|json_query('[].[path, ctime]') }}"
>> 
>> give
>> 
>>  path_ctime:
>>    - [/tmp/test/2022-12-01_1702, 1669938403.313556]
>>    - [/tmp/test/2022-12-01_1701, 1669938401.2335565]
>>    - [/tmp/test/2022-12-01_1703, 1669938405.0495553]
>> 
>> --
>> Vladimir Botka
>> 
>> --
>> 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 ansible-project+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/20221202011038.0ed02422%40gmail.com.
> 
> -- 
> 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 ansible-project+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/CAOCN9rw4aus7R6ZtB6z-oOQeFDa8BgwDyhFPcqVUXqdcLJi9yg%40mail.gmail.com.

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/3A7008EA-6584-4E5D-8CEE-3F674C132306%40gmail.com.

Reply via email to