diff --git a/lib/ansible/modules/files/find.py b/lib/ansible/modules/files/find.py index 590a877117..2a7c6b6d82 100644 --- a/lib/ansible/modules/files/find.py +++ b/lib/ansible/modules/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: