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
Parameter | Type | Description | Required | Default | Choices |
---|---|---|---|---|---|
checksum_algorithm | string | Algorithm to use for file checksum calculation. | false | sha1 | md5, sha1, sha224, sha256, sha384, sha512 |
follow | bool | Whether to follow symbolic links and stat the target instead of the link. | false | false | true, false |
get_attributes | bool | Whether to get extended file attributes (Linux only). | false | false | true, false |
get_checksum | bool | Whether to calculate and return file checksum. | false | false | true, false |
get_mime | bool | Whether to determine and return the MIME type of the file. | false | false | true, false |
path | string | Path to the file or directory to examine. | false |
Outputs
No outputs.