mirror of
https://github.com/zebrajr/ansible.git
synced 2025-12-06 00:19:48 +01:00
file, stat: return disk_usage_bytes (#85909)
Fixes: #70834 Signed-off-by: Abhijeet Kasurde <Akasurde@redhat.com>
This commit is contained in:
parent
169e6bead3
commit
7bd2475a70
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:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return {
|
output = {
|
||||||
'mode': "%04o" % stat.S_IMODE(st.st_mode),
|
'mode': "%04o" % stat.S_IMODE(st.st_mode),
|
||||||
'isdir': stat.S_ISDIR(st.st_mode),
|
'isdir': stat.S_ISDIR(st.st_mode),
|
||||||
'ischr': stat.S_ISCHR(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),
|
'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():
|
def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
|
|
|
||||||
|
|
@ -366,6 +366,12 @@ stat:
|
||||||
type: str
|
type: str
|
||||||
sample: "381700746"
|
sample: "381700746"
|
||||||
version_added: 2.3
|
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
|
import grp
|
||||||
|
|
@ -436,6 +442,8 @@ def format_output(module, path, st):
|
||||||
]:
|
]:
|
||||||
if hasattr(st, other[0]):
|
if hasattr(st, other[0]):
|
||||||
output[other[1]] = getattr(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
|
return output
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,7 @@
|
||||||
- "'xgrp' in stat_result.stat"
|
- "'xgrp' in stat_result.stat"
|
||||||
- "'xoth' in stat_result.stat"
|
- "'xoth' in stat_result.stat"
|
||||||
- "'xusr' in stat_result.stat"
|
- "'xusr' in stat_result.stat"
|
||||||
|
- "'disk_usage_bytes' in stat_result.stat"
|
||||||
|
|
||||||
- name: make a symlink
|
- name: make a symlink
|
||||||
file:
|
file:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user