I have a directory of files I'm looping through and I need to get the filename and possibly other information. The win_stat
module I think uses PowerShell, so it gets the name
, basename
, path
, I think last modified date, etc. Is there a comparable module for use on Linux? I tried the stat
and find
modules, but they only get the full path.
I've also tried different filters, like this one from this question:
lookup('file', item.path) | regex_replace('\u0000',' ')).split() | select('match','^[a-z-_/]*[.]y[a]*ml') | list | first | basename
But this throws an error, or returns nothing. I've also tried just passing the path to basename
:
item.path | basename
But this also does nothing.
This seems like a super simple thing, so I don't understand why it's so complicated to even need a long filter/replace like that.
I suppose I could just split the path and grab the last element:
item.path | split('/') | last
But this seems messy and I would think Ansible would have a better way to get this information about a file?
So what's the best way to accomplish this?