ansible find: get path of a directory

Solution 1:

You get the paths by iterating over the list and pulling out each path individually.

You must do this because find returns a list of dicts about each file. There may be more than one returned, after all.

- name: Show file paths
  debug:
    msg: "{{ item.path }}"
  with_items: "{{ oem.files }}"

Solution 2:

try Jinja2 filters

{{ oem.files | map(attribute='path') | list }}

be avare that this will create a list. If you dont want list you can use this

{{ oem.files | map(attribute='path') | join('') }}

but in case there are more files found, the output will be all paths of found files together.

Tags:

Ansible