ansible find: get path of a directory

Rajiv Nakkana asked:

In find I’m getting the following output, how to filter only the path?

  paths: /jv01
  recurse: yes
  file_type: directory
  patterns: 'agent_13.'
register: oem
- debug:
  var: oem

"oem": {
        "changed": false,
        "examined": 24156,
        "failed": false,
        "files": [
                "atime": 1545128921.5473044,
                "ctime": 1545120358.3347161,
                "dev": 64768,
                "gid": 1027,
                "inode": 67,
                "isblk": false,
                "ischr": false,
                "isdir": true,
                "isfifo": false,
                "isgid": false,
                "islnk": false,
                "isreg": false,
                "issock": false,
                "isuid": false,
                "mode": "0755",
                "mtime": 1545120358.3347161,
                "nlink": 28,
                "path": "/jv01/oracle/agent_13.",
                "rgrp": true,
                "roth": true,
                "rusr": true,
                "size": 4096,
                "uid": 1027,
                "wgrp": false,
                "woth": false,
                "wusr": true,
                "xgrp": true,
                "xoth": true,
                "xusr": true
        "matched": 1,
        "msg": ""

My answer:

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
    msg: "{{ item.path }}"
  with_items: "{{ oem.files }}"

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.