file, stat: return disk_usage_bytes (#85909)

Fixes: #70834

Signed-off-by: Abhijeet Kasurde <Akasurde@redhat.com>
This commit is contained in:
Abhijeet Kasurde
2025-10-24 11:42:58 -07:00
committed by GitHub
parent 169e6bead3
commit 7bd2475a70
4 changed files with 20 additions and 1 deletions

View File

@@ -0,0 +1,4 @@
---
minor_changes:
- file - return disk_usage_bytes fact (https://github.com/ansible/ansible/issues/70834).
- stat - return disk_usage_bytes fact (https://github.com/ansible/ansible/issues/70834).

View File

@@ -430,7 +430,7 @@ def statinfo(st):
except Exception:
pass
return {
output = {
'mode': "%04o" % stat.S_IMODE(st.st_mode),
'isdir': stat.S_ISDIR(st.st_mode),
'ischr': stat.S_ISCHR(st.st_mode),
@@ -463,6 +463,12 @@ def statinfo(st):
'isgid': bool(st.st_mode & stat.S_ISGID),
}
if hasattr(st, 'st_blocks'):
output['blocks'] = st.st_blocks
output['disk_usage_bytes'] = st.st_blocks * 512
return output
def main():
module = AnsibleModule(

View File

@@ -366,6 +366,12 @@ stat:
type: str
sample: "381700746"
version_added: 2.3
disk_usage_bytes:
description: The disk usage of a path in bytes
returned: success, path exists, user can execute the path, filesystem supports st_blocks
type: int
sample: 1024
version_added: '2.21'
"""
import grp
@@ -436,6 +442,8 @@ def format_output(module, path, st):
]:
if hasattr(st, other[0]):
output[other[1]] = getattr(st, other[0])
if other[0] == 'st_blocks':
output['disk_usage_bytes'] = st.st_blocks * 512
return output

View File

@@ -61,6 +61,7 @@
- "'xgrp' in stat_result.stat"
- "'xoth' in stat_result.stat"
- "'xusr' in stat_result.stat"
- "'disk_usage_bytes' in stat_result.stat"
- name: make a symlink
file: