mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Use match() instead of search() for pattern matching
Also related to f48fa3, fix for #8614
This commit is contained in:
parent
f48fa3759a
commit
b4476c238f
1 changed files with 2 additions and 2 deletions
|
@ -162,14 +162,14 @@ class Inventory(object):
|
|||
results = []
|
||||
try:
|
||||
if not pattern_str.startswith('~'):
|
||||
pattern = re.compile('^' + fnmatch.translate(pattern_str))
|
||||
pattern = re.compile(fnmatch.translate(pattern_str))
|
||||
else:
|
||||
pattern = re.compile(pattern_str[1:])
|
||||
except Exception, e:
|
||||
raise errors.AnsibleError('invalid host pattern: %s' % pattern_str)
|
||||
|
||||
for item in items:
|
||||
if pattern.search(getattr(item, item_attr)):
|
||||
if pattern.match(getattr(item, item_attr)):
|
||||
results.append(item)
|
||||
return results
|
||||
|
||||
|
|
Loading…
Reference in a new issue