Skip to main content

stat

stat module

Retrieve file or filesystem status. This module gathers information about files, directories, and other filesystem objects without modifying them.

Examples

- name: Get file statistics
stat:
path: /etc/passwd

- name: Check if file exists
stat:
path: /tmp/myfile
register: file_stat

- name: Get file checksum
stat:
path: /etc/important.conf
get_checksum: true
checksum_algorithm: sha256

- name: Follow symlinks
stat:
path: /usr/bin/python
follow: true

- name: Get MIME type
stat:
path: /var/log/messages
get_mime: true

The stat module provides detailed information about filesystem objects including size, permissions, timestamps, and file type.

Module Capabilities

  • Has Revert: false
  • Provides Variables: None

Inputs

ParameterTypeDescriptionRequiredDefaultChoices
checksum_algorithmstringAlgorithm to use for file checksum calculation.falsesha1md5, sha1, sha224, sha256, sha384, sha512
followboolWhether to follow symbolic links and stat the target instead of the link.falsefalsetrue, false
get_attributesboolWhether to get extended file attributes (Linux only).falsefalsetrue, false
get_checksumboolWhether to calculate and return file checksum.falsefalsetrue, false
get_mimeboolWhether to determine and return the MIME type of the file.falsefalsetrue, false
pathstringPath to the file or directory to examine.false

Outputs

No outputs.