I would like to get the most recent file, in a specific directory, from remote nodes:
I am thinking about running a command similar to:
ls -lrt /tmp/backup |tail -1 | awk '{print $9}
then putting the results of that in the fetch command.
Any suggestions? Does this seem like a good path?
I think this is you only option since Ansible doesn't have any modules to do this, but you can make it a little shorter by removing -l.
ls -t /tmp/backup | head -1
or
ls -tr /tmp/backup | tail -1
Brian_Coca
(Brian Coca)
January 30, 2017, 4:15pm
3
You can do 2 steps, first run the find module in that directory, then using the map filter, sort by mtime and use the last
filter to get the most recent file.