Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

files/stat: add pw_name and md5 sum to stat, and add meaningful? example #3425

Merged
merged 1 commit into from
Jul 12, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 17 additions & 5 deletions library/files/stat
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,18 @@ author: Bruce Pennypacker
'''

EXAMPLES = '''
# Obtain the stats of /etc/foo.conf
- stats: >
path=/etc/foo.conf

# Obtain the stats of /etc/foo.conf, and check that the file still belongs
# to 'root'. Fail otherwise.
- stats: path=/etc/foo.conf
register: st
- fail: msg="Whoops! file ownership has changed"
when: st.stat.pw_name != 'root'
'''

import os
import sys
from stat import *
from pprint import pprint
import pwd

def main():
module = AnsibleModule(
Expand Down Expand Up @@ -99,6 +101,16 @@ def main():
if S_ISDIR(mode) and os.path.islink(path):
d['isdir'] = False
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)
Expand Down