New in version 1.3.
Retrieves facts for a file similar to the linux/unix ‘stat’ command.
parameter | required | default | choices | comments |
---|---|---|---|---|
checksum_algorithm (added in 2.0) |
no | sha1 |
|
Algorithm to determine checksum of file. Will throw an error if the host is unable to use specified algorithm. aliases: checksum_algo, checksum |
follow |
no | Whether to follow symlinks | ||
get_checksum (added in 1.8) |
no | True | Whether to return a checksum of the file (default sha1) | |
get_md5 |
no | True | Whether to return the md5 sum of the file. Will return None if we're unable to use md5 (Common for FIPS-140 compliant systems) | |
mime (added in 2.1) |
no |
|
Use file magic and return data about the nature of the file. this uses the 'file' utility found on most Linux/Unix systems. This will add both `mime_type` and 'charset' fields to the return, if possible. aliases: mime_type, mime-type | |
path |
yes | The full path of the file/object to get the facts of |
# Obtain the stats of /etc/foo.conf, and check that the file still belongs # to 'root'. Fail otherwise. - stat: path=/etc/foo.conf register: st - fail: msg="Whoops! file ownership has changed" when: st.stat.pw_name != 'root' # Determine if a path exists and is a symlink. Note that if the path does # not exist, and we test sym.stat.islnk, it will fail with an error. So # therefore, we must test whether it is defined. # Run this to understand the structure, the skipped ones do not pass the # check performed by 'when' - stat: path=/path/to/something register: sym - debug: msg="islnk isn't defined (path doesn't exist)" when: sym.stat.islnk is not defined - debug: msg="islnk is defined (path must exist)" when: sym.stat.islnk is defined - debug: msg="Path exists and is a symlink" when: sym.stat.islnk is defined and sym.stat.islnk - debug: msg="Path exists and isn't a symlink" when: sym.stat.islnk is defined and sym.stat.islnk == False # Determine if a path exists and is a directory. Note that we need to test # both that p.stat.isdir actually exists, and also that it's set to true. - stat: path=/path/to/something register: p - debug: msg="Path exists and is a directory" when: p.stat.isdir is defined and p.stat.isdir # Don't do md5 checksum - stat: path=/path/to/myhugefile get_md5=no # Use sha256 to calculate checksum - stat: path=/path/to/something checksum_algorithm=sha256
Common return values are documented here Common Return Values, the following are the fields unique to this module:
name | description | returned | type | sample | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
stat | dictionary containing all the stat data | success | dictionary | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
contains: |
|
For more information on what this means please read Core Modules
For help in developing on modules, should you be so inclined, please read Community Information & Contributing, Helping Testing PRs and Developing Modules.