Use Ansible module *find* and sort the directories by *ctime*. For example, given the tree
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/20221202011038.0ed02422%40gmail.com.
pgpuhZVpCLY4r.pgp
Description: OpenPGP digital signature
