Return a list of files based on specific criteria
- Return a list of files based on specified criteria.
- Multiple criteria are AND'd together.
- For non-Windows targets, use the :ref:`ansible.builtin.find <ansible.builtin.find_module>` module instead.
Note
- When scanning directories with a large number of files containing lots of data it is recommended to set
get_checksum=false
. This will speed up the time it takes to scan the folders as getting a checksum needs to read the contents of every file it returns.
- 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: yes
- 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: yes
- name: Find files in directory while following symlinks
ansible.windows.win_find:
paths: D:\Temp
recurse: yes
follow: yes
- 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: yes
checksum_algorithm: sha256
- name: Find files and do not return the checksum
ansible.windows.win_find:
paths: C:\Temp
get_checksum: no
Common return values are documented here, the following are the fields unique to this module:
- Jordan Borean (@jborean93)