From b4476c238f38d09de918782e6708d0d4d1b57c7f Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Thu, 14 Aug 2014 12:26:52 -0500 Subject: [PATCH] Use match() instead of search() for pattern matching Also related to f48fa3, fix for #8614 --- lib/ansible/inventory/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ansible/inventory/__init__.py b/lib/ansible/inventory/__init__.py index 1ff15c0581e..a0f8a399427 100644 --- a/lib/ansible/inventory/__init__.py +++ b/lib/ansible/inventory/__init__.py @@ -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