mirror of
https://github.com/ansible/ansible.git
synced 2025-11-30 23:16:08 +07:00
file, stat: return disk_usage_bytes (#85909)
Fixes: #70834 Signed-off-by: Abhijeet Kasurde <Akasurde@redhat.com>
This commit is contained in:
4
changelogs/fragments/du_size.yml
Normal file
4
changelogs/fragments/du_size.yml
Normal 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).
|
||||
@@ -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(
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user