community.openwrt.stat module – Retrieve file or file system status on OpenWrt targets

Note

This module is part of the community.openwrt collection (version 0.5.0).

It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.openwrt.

To use it in a playbook, specify: community.openwrt.stat.

Synopsis

Note

This module has a corresponding action plugin.

Parameters

Parameter

Comments

checksum_algorithm

aliases: checksum_algo, checksum

string

Algorithm to use for checksumming the file.

Choices:

  • "md5"

  • "sha1" ← (default)

  • "sha224"

  • "sha256"

  • "sha384"

  • "sha512"

follow

boolean

Whether to follow symlinks.

Choices:

  • false

  • true

get_checksum

boolean

Whether to get the checksum of the file.

Uses the algorithm specified in checksum_algorithm.

Choices:

  • false

  • true ← (default)

get_md5

boolean

Whether to get the MD5 checksum of the file.

Choices:

  • false

  • true ← (default)

get_mime

boolean

Whether to get the MIME type of the file.

Note that this is not fully implemented and returns unknown.

Choices:

  • false

  • true ← (default)

path

string / required

The full path of the file/directory to get the facts of.

Attributes

Attribute

Support

Description

check_mode

Support: full

This action does not modify state.

Can run in check_mode and return changed status prediction without modifying target.

diff_mode

Support: N/A

This action does not modify state.

Returns details on what has changed (or possibly needs changing in check_mode), when in diff mode.

platform

Platform: OpenWrt

Target platform for this module.

Examples

- name: Get stats of a file
  community.openwrt.stat:
    path: /etc/config/network
  register: network_stat

- name: Check if file exists
  community.openwrt.stat:
    path: /tmp/myfile
  register: file_check

- name: Get file checksum
  community.openwrt.stat:
    path: /etc/config/system
    checksum_algorithm: sha256
  register: file_hash

- name: Fail if path does not exist
  community.openwrt.stat:
    path: /etc/important_file
  register: stat_result
  failed_when: not stat_result.stat.exists

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key

Description

stat

dictionary

Dictionary containing all file stat information.

Returned: always

charset

string

Character set of the file.

Returned: when file exists

Sample: "unknown"

checksum

string

Hash of the file using the specified algorithm.

Returned: when get_checksum=true and file is readable

Sample: "4e1243bd22c66e76c2ba9eddc1f91394e57f9f83"

ctime

integer

Last change time in seconds since epoch.

Returned: when file exists

Sample: 1701788400

dev

integer

Device identifier.

Returned: when file exists

executable

boolean

Whether the file is executable by the current user.

Returned: when file exists

Sample: false

exists

boolean

Whether the file exists.

Returned: always

Sample: true

gid

integer

Numeric group ID of the owner.

Returned: when file exists

Sample: 0

gr_name

string

Group name of the owner.

Returned: when file exists

Sample: "root"

inode

integer

Inode number of the file.

Returned: when file exists

Sample: 12345

isblk

boolean

Whether the path is a block device.

Returned: when file exists

Sample: false

ischr

boolean

Whether the path is a character device.

Returned: when file exists

Sample: false

isdir

boolean

Whether the path is a directory.

Returned: when file exists

Sample: false

isfifo

boolean

Whether the path is a FIFO.

Returned: when file exists

Sample: false

isgid

boolean

Whether the file is owned by the current group.

Returned: when file exists

Sample: true

islnk

boolean

Whether the path is a symbolic link.

Returned: when file exists

Sample: false

isreg

boolean

Whether the path is a regular file.

Returned: when file exists

Sample: true

issock

boolean

Whether the path is a socket.

Returned: when file exists

Sample: false

isuid

boolean

Whether the file is owned by the current user.

Returned: when file exists

Sample: true

lnk_source

string

Original path when follow=true and path is a symlink.

Returned: when following a symlink

Sample: "/tmp/link"

md5

string

MD5 hash of the file.

Returned: when get_md5=true and file is readable

Sample: "9a8ad92c50cae39aa2c5604fd0ab6d8c"

mime_type

string

MIME type of the file.

Returned: when file exists

Sample: "unknown"

mode

string

Unix permissions of the file in octal.

Returned: when file exists

Sample: "0644"

mtime

integer

Last modification time in seconds since epoch.

Returned: when file exists

Sample: 1701788400

integer

Number of hard links to the file.

Returned: when file exists

Sample: 1

path

string

The full path to the file.

Returned: always

Sample: "/etc/config/network"

pw_name

string

User name of the owner.

Returned: when file exists

Sample: "root"

readable

boolean

Whether the file is readable by the current user.

Returned: when file exists

Sample: true

rgrp

boolean

Whether the group has read permission.

Returned: when file exists

Sample: true

roth

boolean

Whether others have read permission.

Returned: when file exists

Sample: true

rusr

boolean

Whether the owner has read permission.

Returned: when file exists

Sample: true

size

integer

Size of the file in bytes.

Returned: when file exists

Sample: 1024

uid

integer

Numeric user ID of the owner.

Returned: when file exists

Sample: 0

wgrp

boolean

Whether the group has write permission.

Returned: when file exists

Sample: false

woth

boolean

Whether others have write permission.

Returned: when file exists

Sample: false

writeable

boolean

Whether the file is writeable by the current user.

Returned: when file exists

Sample: true

wusr

boolean

Whether the owner has write permission.

Returned: when file exists

Sample: true

xgrp

boolean

Whether the group has execute permission.

Returned: when file exists

Sample: false

xoth

boolean

Whether others have execute permission.

Returned: when file exists

Sample: false

xusr

boolean

Whether the owner has execute permission.

Returned: when file exists

Sample: false

Authors

  • Markus Weippert (@gekmihesg)