Skip to content

Instantly share code, notes, and snippets.

@Finkregh
Created January 21, 2020 09:21
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save Finkregh/c7aafa925f28c531cf1b3eebfdcd474f to your computer and use it in GitHub Desktop.
Save Finkregh/c7aafa925f28c531cf1b3eebfdcd474f to your computer and use it in GitHub Desktop.
ansible: get files from directory - only names without path
- name: "get files from dir"
find:
paths: "/some/dir/foo"
register: found_files
- name: print file names without path
debug:
msg: "{{ found_files['files'] | map(attribute='path') | map('regex_replace','^.*/(.*)$','\\1') | list }}"
@eldadpuzach
Copy link

Thank You!🙏

@CrissLoaiza
Copy link

perfect 👍

@binhoul
Copy link

binhoul commented Nov 11, 2022

cool

@smudge1977
Copy link

Perfect thanks
"{{ daemon_binaries['files'] | map(attribute='path') | map('regex_replace', '^.*/(.*)$', '\\1') | list }}"
Just to make ansible-lint happy

@grizmin
Copy link

grizmin commented Mar 22, 2023

Using a basename filter is more appropriate.
msg: "{{ found_files['files'] | map(attribute='path') | map('basename') | list }}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment