ansible.windows.win_find 模块 – 根据特定条件返回文件列表
注意
此模块是 ansible.windows 集合(版本 2.5.0)的一部分。
如果您正在使用 ansible
包,您可能已经安装了这个集合。它不包含在 ansible-core
中。要检查是否已安装,请运行 ansible-galaxy collection list
。
要安装它,请使用:ansible-galaxy collection install ansible.windows
。
要在 playbook 中使用它,请指定:ansible.windows.win_find
。
概要
根据指定的条件返回文件列表。
多个条件之间是“与”的关系。
对于非 Windows 目标,请改用 ansible.builtin.find 模块。
参数
参数 |
注释 |
---|---|
选择年龄等于或大于指定时间的文件或文件夹。 使用负年龄查找等于或小于指定时间的文件。 您可以通过指定这些单词的首字母来选择秒、分钟、小时、天或周(例如,“2s”、“10d”、1w”)。 |
|
选择我们用于比较 默认情况下,我们比较的属性是上次修改时间。 选择
|
|
确定文件校验和的算法。 如果主机无法使用指定的算法,则会抛出错误。 选择
|
|
设置要下降的最大级别数。 将 recurse 设置为 默认深度是不受限制的。 |
|
要搜索的文件类型。 选择
|
|
将其设置为 这需要与 选择
|
|
是否在返回信息中返回文件的校验和(默认 sha1),使用 选择
|
|
将其设置为包括隐藏的文件或文件夹。 选择
|
|
要在其中搜索文件或文件夹的目录路径列表。 这可以作为单个路径或路径列表提供。 |
|
一个或多个(powershell 或 regex)模式,用于比较文件名。 模式匹配的类型由 模式根据文件名限制要返回的文件或文件夹列表。 要匹配文件,它只需要与提供的列表中的一个模式匹配。 |
|
将递归下降到目录中查找文件或文件夹。 选择
|
|
选择大小等于或大于指定大小的文件或文件夹。 使用负值查找等于或小于指定大小的文件。 您可以使用字节类型后缀指定大小,即 kilo = k,mega = m... 不会评估符号链接的大小。 |
|
如果设置为 选择
|
说明
注意
扫描包含大量数据的具有大量文件的目录时,建议设置
get_checksum=false
。这将加快扫描文件夹所需的时间,因为获取校验和需要读取返回的每个文件的内容。
示例
- name: Find files in path
ansible.windows.win_find:
paths: D:\Temp
- name: Find hidden files in path
ansible.windows.win_find:
paths: D:\Temp
hidden: true
- name: Find files in multiple paths
ansible.windows.win_find:
paths:
- C:\Temp
- D:\Temp
- name: Find files in directory while searching recursively
ansible.windows.win_find:
paths: D:\Temp
recurse: true
- name: Find files in directory while following symlinks
ansible.windows.win_find:
paths: D:\Temp
recurse: true
follow: true
- name: Find files with .log and .out extension using powershell wildcards
ansible.windows.win_find:
paths: D:\Temp
patterns: ['*.log', '*.out']
- name: Find files in path based on regex pattern
ansible.windows.win_find:
paths: D:\Temp
patterns: out_\d{8}-\d{6}.log
- name: Find files older than 1 day
ansible.windows.win_find:
paths: D:\Temp
age: 86400
- name: Find files older than 1 day based on create time
ansible.windows.win_find:
paths: D:\Temp
age: 86400
age_stamp: ctime
- name: Find files older than 1 day with unit syntax
ansible.windows.win_find:
paths: D:\Temp
age: 1d
- name: Find files newer than 1 hour
ansible.windows.win_find:
paths: D:\Temp
age: -3600
- name: Find files newer than 1 hour with unit syntax
ansible.windows.win_find:
paths: D:\Temp
age: -1h
- name: Find files larger than 1MB
ansible.windows.win_find:
paths: D:\Temp
size: 1048576
- name: Find files larger than 1GB with unit syntax
ansible.windows.win_find:
paths: D:\Temp
size: 1g
- name: Find files smaller than 1MB
ansible.windows.win_find:
paths: D:\Temp
size: -1048576
- name: Find files smaller than 1GB with unit syntax
ansible.windows.win_find:
paths: D:\Temp
size: -1g
- name: Find folders/symlinks in multiple paths
ansible.windows.win_find:
paths:
- C:\Temp
- D:\Temp
file_type: directory
- name: Find files and return SHA256 checksum of files found
ansible.windows.win_find:
paths: C:\Temp
get_checksum: true
checksum_algorithm: sha256
- name: Find files and do not return the checksum
ansible.windows.win_find:
paths: C:\Temp
get_checksum: false
返回值
常见的返回值记录在此处,以下是此模块独有的字段
键 |
描述 |
---|---|
检查的文件/文件夹数量。 返回值: 始终 示例: |
|
与条件匹配的文件/文件夹的信息,作为每个匹配文件的字典元素列表返回。这些条目按路径值按字母顺序排序。 返回值: 成功 |
|
路径处文件的原始属性形式。 返回值: 成功,路径存在 示例: |
|
基于指定的 checksum_algorithm 的文件校验和。 返回值: 成功,路径存在,路径是文件,get_checksum == True 示例: |
|
文件创建时间,以自 epoch 以来的秒数表示。 返回值: 成功,路径存在 示例: |
|
文件路径的扩展名。 返回: 成功,路径存在,路径是文件 示例: |
|
文件名。 返回值: 成功,路径存在 示例: |
|
指向同一文件的其他文件列表(硬链接),不包括当前文件。 返回值: 成功,路径存在 示例: |
|
路径是否已准备好进行存档。 返回值: 成功,路径存在 示例: |
|
路径是否为目录。 返回值: 成功,路径存在 示例: |
|
路径是否隐藏。 返回值: 成功,路径存在 示例: |
|
路径是否为连接点。 返回值: 成功,路径存在 示例: |
|
路径是否为符号链接。 返回值: 成功,路径存在 示例: |
|
路径是否为只读。 返回值: 成功,路径存在 示例: |
|
路径是否为常规文件。 返回值: 成功,路径存在 示例: |
|
路径是否为共享。 返回值: 成功,路径存在 示例: |
|
文件最后访问时间,以自 epoch 以来的秒数表示。 返回值: 成功,路径存在 示例: |
|
文件最后修改时间,以自 epoch 以来的秒数表示。 返回值: 成功,路径存在 示例: |
|
为远程文件系统规范化的符号链接的目标。 返回: 成功,路径存在,路径是符号链接或连接点 示例: |
|
符号链接的目标。请注意,相对路径保持相对,如果不是链接,则返回 null。 返回: 成功,路径存在,路径是符号链接或连接点 示例: |
|
指向该文件的链接数(硬链接) 返回值: 成功,路径存在 示例: |
|
文件的所有者。 返回值: 成功,路径存在 示例: |
|
文件的完整绝对路径。 返回值: 成功,路径存在 示例: |
|
如果文件夹已共享,则为共享名称。 返回: 成功,路径存在,路径是目录且 isshared == True 示例: |
|
文件的大小(以字节为单位)。 返回: 成功,路径存在,路径是文件 示例: |
|
符合条件的文件/文件夹数量。 返回值: 始终 示例: |