added regex support to find, also added 'singular' aliasess to patterns and paths
This commit is contained in:
parent
14f32de7a6
commit
bc4b40d8e7
1 changed files with 15 additions and 11 deletions
|
@ -50,17 +50,18 @@ options:
|
|||
required: false
|
||||
default: '*'
|
||||
description:
|
||||
- One or more (shell type) file glob patterns, which restrict the list of files to be returned to
|
||||
- One or more (shell type) patterns, which restrict the list of files to be returned to
|
||||
those whose basenames match at least one of the patterns specified. Multiple patterns can be
|
||||
specified using a list.
|
||||
specified using a list. The patterns can be simple shell globs or a python regex prefixed by a '~'.
|
||||
aliases: ['pattern']
|
||||
contains:
|
||||
required: false
|
||||
default: null
|
||||
description:
|
||||
- One or more re patterns which should be matched against the file content
|
||||
- One or more re patterns which should be matched against the file content
|
||||
paths:
|
||||
required: true
|
||||
aliases: [ "name" ]
|
||||
aliases: [ "name", "path" ]
|
||||
description:
|
||||
- List of paths to the file or directory to search. All paths must be fully qualified.
|
||||
file_type:
|
||||
|
@ -121,8 +122,9 @@ EXAMPLES = '''
|
|||
# Recursively find /var/tmp files with last access time greater than 3600 seconds
|
||||
- find: paths="/var/tmp" age="3600" age_stamp=atime recurse=yes
|
||||
|
||||
# find /var/log files equal or greater than 10 megabytes ending with .log or .log.gz
|
||||
- find: paths="/var/tmp" patterns="*.log","*.log.gz" size="10m"
|
||||
# find /var/log files equal or greater than 10 megabytes ending with .old or .log.gz via regex
|
||||
- find: paths="/var/tmp" patterns="~.*\.(?:old|log\.gz)$" size="10m"
|
||||
|
||||
'''
|
||||
|
||||
RETURN = '''
|
||||
|
@ -157,9 +159,11 @@ def pfilter(f, patterns=None):
|
|||
if patterns is None:
|
||||
return True
|
||||
for p in patterns:
|
||||
if fnmatch.fnmatch(f, p):
|
||||
return True
|
||||
return False
|
||||
if p.startswith('~'):
|
||||
r = re.compile(p[1:])
|
||||
return r.match(f)
|
||||
else:
|
||||
return fnmatch.fnmatch(f, p)
|
||||
|
||||
|
||||
def agefilter(st, now, age, timestamp):
|
||||
|
@ -236,8 +240,8 @@ def statinfo(st):
|
|||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec = dict(
|
||||
paths = dict(required=True, aliases=['name'], type='list'),
|
||||
patterns = dict(default=['*'], type='list'),
|
||||
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'),
|
||||
age = dict(default=None, type='str'),
|
||||
|
|
Loading…
Reference in a new issue