1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Merge pull request #6221 from risaacson/pull_6176

stat module: mode is now returned as an octal and md5 call can be skipped.
This commit is contained in:
Richard Isaacson 2014-02-28 11:07:59 -06:00
commit e798b558aa

View file

@ -34,6 +34,12 @@ options:
required: false
default: no
aliases: []
get_md5:
description:
- Whether to return the md5 sum of the file
required: false
default: yes
aliases: []
author: Bruce Pennypacker
'''
@ -51,6 +57,9 @@ EXAMPLES = '''
register: p
- debug: msg="Path exists and is a directory"
when: p.stat.isdir is defined and p.stat.isdir == true
# Don't do md5 checksum
- stat: path=/path/to/myhugefile get_md5=no
'''
import os
@ -62,7 +71,8 @@ def main():
module = AnsibleModule(
argument_spec = dict(
path = dict(required=True),
follow = dict(default='no', type='bool')
follow = dict(default='no', type='bool'),
get_md5 = dict(default='yes', type='bool')
),
supports_check_mode = True
)
@ -70,6 +80,7 @@ def main():
path = module.params.get('path')
path = os.path.expanduser(path)
follow = module.params.get('follow')
get_md5 = module.params.get('get_md5')
try:
if follow:
@ -88,7 +99,7 @@ def main():
# back to ansible
d = {
'exists' : True,
'mode' : S_IMODE(mode),
'mode' : "%04o" % S_IMODE(mode),
'isdir' : S_ISDIR(mode),
'ischr' : S_ISCHR(mode),
'isblk' : S_ISBLK(mode),
@ -121,7 +132,7 @@ def main():
if S_ISLNK(mode):
d['lnk_source'] = os.path.realpath(path)
if S_ISREG(mode):
if S_ISREG(mode) and get_md5:
d['md5'] = module.md5(path)
try: