我想列出目录中所有以'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