summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Wittman <david@wittman.com>2015-12-02 11:27:44 -0600
committerBrian Coca <bcoca@users.noreply.github.com>2016-11-16 21:11:14 -0500
commit9f200a9cb90d42b63ab506e3956340dfabf51f24 (patch)
tree86ea1a91848f1a9f246f3ed8ef15c190ac29d7b3
parenta257f9cc9c5e481ad7902db53fc46f4001adcbad (diff)
downloadansible-modules-core-9f200a9cb90d42b63ab506e3956340dfabf51f24.tar.gz
Add 'link' file_type to find_module
- Adds the 'link' file_type for finding symbolic or hard links - Use `os.lstat` instead of `os.stat` to prevent the following of links when statting the file.
-rw-r--r--files/find.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/files/find.py b/files/find.py
index 590a8771..2a7c6b6d 100644
--- a/files/find.py
+++ b/files/find.py
@@ -66,7 +66,7 @@ options:
required: false
description:
- Type of file to select
- choices: [ "file", "directory" ]
+ choices: [ "file", "directory", "link" ]
default: "file"
recurse:
required: false
@@ -275,7 +275,7 @@ def main():
paths = dict(required=True, aliases=['name','path'], type='list'),
patterns = dict(default=['*'], type='list', aliases=['pattern']),
contains = dict(default=None, type='str'),
- file_type = dict(default="file", choices=['file', 'directory'], type='str'),
+ file_type = dict(default="file", choices=['file', 'directory', 'link'], type='str'),
age = dict(default=None, type='str'),
age_stamp = dict(default="mtime", choices=['atime','mtime','ctime'], type='str'),
size = dict(default=None, type='str'),
@@ -331,7 +331,7 @@ def main():
continue
try:
- st = os.stat(fsname)
+ st = os.lstat(fsname)
except:
msg+="%s was skipped as it does not seem to be a valid file or it cannot be accessed\n" % fsname
continue
@@ -354,6 +354,11 @@ def main():
r['checksum'] = module.sha1(fsname)
filelist.append(r)
+ elif stat.S_ISLNK(st.st_mode) and params['file_type'] == 'link':
+ if pfilter(fsobj, params['patterns'], params['use_regex']) and agefilter(st, now, age, params['age_stamp']):
+ r.update(statinfo(st))
+ filelist.append(r)
+
if not params['recurse']:
break
else: