mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #3425 from jpmens/stat1
files/stat: add pw_name and md5 sum to stat, and add meaningful? example
This commit is contained in:
commit
2631823b8b
1 changed files with 17 additions and 5 deletions
|
@ -32,16 +32,18 @@ author: Bruce Pennypacker
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
# Obtain the stats of /etc/foo.conf
|
# Obtain the stats of /etc/foo.conf, and check that the file still belongs
|
||||||
- stats: >
|
# to 'root'. Fail otherwise.
|
||||||
path=/etc/foo.conf
|
- stats: path=/etc/foo.conf
|
||||||
|
register: st
|
||||||
|
- fail: msg="Whoops! file ownership has changed"
|
||||||
|
when: st.stat.pw_name != 'root'
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from stat import *
|
from stat import *
|
||||||
from pprint import pprint
|
import pwd
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
|
@ -100,6 +102,16 @@ def main():
|
||||||
d['isdir'] = False
|
d['isdir'] = False
|
||||||
d['islnk'] = True
|
d['islnk'] = True
|
||||||
|
|
||||||
|
if S_ISREG(mode):
|
||||||
|
d['md5'] = module.md5(path)
|
||||||
|
|
||||||
|
try:
|
||||||
|
pw = pwd.getpwuid(st.st_uid)
|
||||||
|
|
||||||
|
d['pw_name'] = pw.pw_name
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
module.exit_json(changed=False, stat=d)
|
module.exit_json(changed=False, stat=d)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue