大网数据广告活动
服务器运维问答

ansible find: get path of a directory

· 52CE 我爱测

In find I'm getting the following output, how to filter only the path? find: paths: /jv01 recurse: yes file_type: directory patterns: 'agent_13.3.0.0.0' register: oem - debug: var: oem "oem": { "changed": false, "examined": 24156…

问题原文

原帖链接 · Rajiv Nakkana · CC BY-SA 4.0

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

find:
  paths: /jv01
  recurse: yes
  file_type: directory
  patterns: 'agent_13.3.0.0.0'
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.3.0.0.0",
                "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": ""
    }
}

社区高分解答

原帖链接 · Lucky · CC BY-SA 4.0

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-12-18)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。