【发布时间】:2020-07-29 18:59:48
【问题描述】:
在 Ansible v2.8.2 中,如何搜索目录树的子集,例如“home/ansible”?
我尝试过使用查找模块:
- name: Find ansible directory
become: true
find:
paths: /
recurse: yes
file_type: directory
use_regex: yes
patterns: 'home/ansible'
register: ansible_dirs
- name: post ansible dirs
debug:
msg:
- "{{ ansible_dirs }}"
我收到错误:/proc/20828/task/20828/fd/6 was skipped as it does not seem to be a valid file or it cannot be accessed
如果我将模式更改为“home”或“ansible”,它会起作用,但会给我更多的结果,然后我需要。
我想我可以采用这个更大的结果集并将其缩减为我需要的,但我希望有一种开箱即用的方法可以使用。
非常感谢任何帮助,谢谢!
【问题讨论】:
-
来自文档:
The pattern is matched against the file base name, excluding the directory.所以你试图做的事情是行不通的(至少使用 find 模块)。如果通过shellmodule 可用,您可以考虑在这种特定情况下使用locate。我不知道有任何 ansible 模块能够满足您的要求(但我很乐意被证明是错误的)。 -
@Zeitounator 这也是我的想法,但我希望我也错了:-)
标签: regex linux design-patterns ansible find