From 53d71a3949d1ab5cee665bae1f04a00dfff99017 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Tue, 25 Feb 2014 21:33:14 -0500 Subject: [PATCH 1/3] added octal representation of mode and made md5 checksumming optional Signed-off-by: Brian Coca --- library/files/stat | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/library/files/stat b/library/files/stat index 6e7dcd62bc..26a2f6953e 100644 --- a/library/files/stat +++ b/library/files/stat @@ -34,6 +34,12 @@ options: required: false default: no aliases: [] + get_md5: + description: + - Whether to return the md5 sum o fthe 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: @@ -80,7 +91,7 @@ def main(): if e.errno == errno.ENOENT: d = { 'exists' : False } module.exit_json(changed=False, stat=d) - + module.fail_json(msg = e.strerror) mode = st.st_mode @@ -89,6 +100,7 @@ def main(): d = { 'exists' : True, 'mode' : S_IMODE(mode), + 'octal' : "%04o" % S_IMODE(mode), 'isdir' : S_ISDIR(mode), 'ischr' : S_ISCHR(mode), 'isblk' : S_ISBLK(mode), @@ -121,7 +133,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: @@ -130,7 +142,7 @@ def main(): d['pw_name'] = pw.pw_name except: pass - + module.exit_json(changed=False, stat=d) From 809b714bfc282c181d0a237079613145a014aa54 Mon Sep 17 00:00:00 2001 From: Richard C Isaacson Date: Fri, 28 Feb 2014 10:42:20 -0600 Subject: [PATCH 2/3] Replace mode with octal renaming to mode. Closes GH-6176 This way for mode we return in an octal format which is immediately usable compared to transforming it later. --- library/files/stat | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/library/files/stat b/library/files/stat index 26a2f6953e..ae4b58923f 100644 --- a/library/files/stat +++ b/library/files/stat @@ -99,8 +99,7 @@ def main(): # back to ansible d = { 'exists' : True, - 'mode' : S_IMODE(mode), - 'octal' : "%04o" % S_IMODE(mode), + 'mode' : "%04o" % S_IMODE(mode), 'isdir' : S_ISDIR(mode), 'ischr' : S_ISCHR(mode), 'isblk' : S_ISBLK(mode), From f17e549ff92080652e17fdf451cd9545845a4b86 Mon Sep 17 00:00:00 2001 From: Richard C Isaacson Date: Fri, 28 Feb 2014 11:02:58 -0600 Subject: [PATCH 3/3] Typo fix. --- library/files/stat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/files/stat b/library/files/stat index ae4b58923f..2839ca8e06 100644 --- a/library/files/stat +++ b/library/files/stat @@ -36,7 +36,7 @@ options: aliases: [] get_md5: description: - - Whether to return the md5 sum o fthe file + - Whether to return the md5 sum of the file required: false default: yes aliases: []