搜索所有者与可见的剧本

  • 本文关键字:所有者 搜索 ansible
  • 更新时间 :
  • 英文 :


我想列出目录中所有以'a'开头的文件,我有一个这样的剧本

- name: Recursively find 
find:
paths: "/tmp"
age: "6d"
age_stamp: ctime
file_type: any
patterns: "*"
recurse: no
register: output

Q:">列出目录中所有文件名以'a'开头的文件的所有者">

A:例如,给定树
shell> tree -u tmp
tmp
├── [admin   ]  file1
├── [admin   ]  file2
└── [user1   ]  file3

查找第一个任务中的所有文件,并在第二个任务中选择所有者

- find:
paths: tmp
register: output
- debug:
msg: "{{ item.path }}"
loop: "{{ output.files|selectattr('pw_name', 'match', '^a.*$')|list }}"

msg: tmp/file2
msg: tmp/file1

最新更新