You are reading an unmaintained version of the Ansible documentation. Unmaintained Ansible versions can contain unfixed security vulnerabilities (CVE). Please upgrade to a maintained version. See the latest Ansible documentation.
find - Return a list of files based on specific criteria¶
Select files whose age is equal to or greater than the specified time. Use a negative age to find files equal to or less than the specified time. You can choose seconds, minutes, hours, days, or weeks by specifying the first letter of any of those words (e.g., "1w").
age_stamp
no
mtime
atime
ctime
mtime
Choose the file property against which we compare age.
contains
no
One or more regex patterns which should be matched against the file content.
file_type
no
file
any
directory
file
link
Type of file to select.
The 'link' and 'any' choices were added in version 2.3.
follow
no
no
no
yes
Set this to true to follow symlinks in path for systems with python 2.6+.
get_checksum
no
no
no
yes
Set this to true to retrieve a file's sha1 checksum.
hidden
no
no
no
yes
Set this to true to include hidden files, otherwise they'll be ignored.
paths
yes
List of paths of directories to search. All paths must be fully qualified.
aliases: name, path
patterns
no
*
One or more (shell or regex) patterns, which type is controlled by use_regex option.
The patterns restrict the list of files to be returned to those whose basenames match at least one of the patterns specified. Multiple patterns can be specified using a list.
aliases: pattern
recurse
no
no
no
yes
If target is a directory, recursively descend into the directory looking for files.
size
no
Select files whose size is equal to or greater than the specified size. Use a negative size to find files equal to or less than the specified size. Unqualified values are in bytes, but b, k, m, g, and t can be appended to specify bytes, kilobytes, megabytes, gigabytes, and terabytes, respectively. Size is not evaluated for directories.
use_regex
no
no
no
yes
If false the patterns are file globs (shell) if true they are python regexes.
-name:Recursively find /tmp files older than 2 daysfind:paths:/tmpage:2drecurse:yes-name:Recursively find /tmp files older than 4 weeks and equal or greater than 1 megabyte-find:paths:/tmpage:4wsize:1mrecurse:yes-name:Recursively find /var/tmp files with last access time greater than 3600 seconds-find:paths:/var/tmpage:3600age_stamp:atimerecurse:yes-name:Find /var/log files equal or greater than 10 megabytes ending with .old or .log.gz-find:paths:/var/logpatterns:'*.old,*.log.gz'size:10m# Note that YAML double quotes require escaping backslashes but yaml single quotes do not.-name:Find /var/log files equal or greater than 10 megabytes ending with .old or .log.gz via regex-find:paths:/var/logpatterns:"^.*?\\.(?:old|log\\.gz)$"size:10muse_regex:yes
This module is flagged as stableinterface which means that the maintainers for this module guarantee that no backward incompatible interface changes will be made.
For more information about Red Hat’s this support of this module, please
refer to this knowledge base article<https://access.redhat.com/articles/rhel-top-support-policies>