From fa6ffa1dbdc83f5fa8aa5361d2d72a5cc63d8ee5 Mon Sep 17 00:00:00 2001 From: Abhijit Menon-Sen Date: Sun, 23 Aug 2015 13:54:22 +0530 Subject: [PATCH] Remove & and ! pattern prefixes as early as possible Now everything under _match_one_pattern can ignore them. This also means that we can use the cache to return the same results for 'foo' and '!foo'. --- lib/ansible/inventory/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/ansible/inventory/__init__.py b/lib/ansible/inventory/__init__.py index 7d4263bdbc..c105b7e5c0 100644 --- a/lib/ansible/inventory/__init__.py +++ b/lib/ansible/inventory/__init__.py @@ -229,10 +229,13 @@ class Inventory(object): def _match_one_pattern(self, pattern): """ Takes a single pattern (i.e., not "p1:p2") and returns a list of - matching hosts names. Does not take negatives or intersections + matching host names. Does not take negatives or intersections into account. """ + if pattern.startswith("&") or pattern.startswith("!"): + pattern = pattern[1:] + if pattern in self._pattern_cache: return self._pattern_cache[pattern] @@ -308,9 +311,6 @@ class Inventory(object): hosts = [] hostnames = set() - # ignore any negative checks here, this is handled elsewhere - pattern = pattern.replace("!","").replace("&", "") - def __append_host_to_results(host): if host.name not in hostnames: hostnames.add(host.name)