From 307a3e8a9ce4109998919678d0615fa2b0da9756 Mon Sep 17 00:00:00 2001 From: Dan Slimmon Date: Thu, 10 Jul 2014 00:08:12 +0000 Subject: [PATCH 1/2] Fixed regex square-bracket bug. Regexes were being parsed like ordinary ansible host patterns, so square-bracket groups were getting interpolated wrongly. --- lib/ansible/inventory/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/ansible/inventory/__init__.py b/lib/ansible/inventory/__init__.py index 830d74c01ef..64bae5d815e 100644 --- a/lib/ansible/inventory/__init__.py +++ b/lib/ansible/inventory/__init__.py @@ -235,6 +235,10 @@ class Inventory(object): a tuple of (start, stop) or None """ + # Do not parse regexes for enumeration info + if pattern.startswith('~'): + return (pattern, None) + # The regex used to match on the range, which can be [x] or [x-y]. pattern_re = re.compile("^(.*)\[([-]?[0-9]+)(?:(?:-)([0-9]+))?\](.*)$") m = pattern_re.match(pattern) From 6ad09f18255fe8af8b74b4a3a38fe759fab58beb Mon Sep 17 00:00:00 2001 From: Dan Slimmon Date: Thu, 10 Jul 2014 00:21:38 +0000 Subject: [PATCH 2/2] Added test for regex grouping bug fixed in 307a3e --- test/units/TestInventory.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/units/TestInventory.py b/test/units/TestInventory.py index e8f85adbd4a..65da05dba3c 100644 --- a/test/units/TestInventory.py +++ b/test/units/TestInventory.py @@ -274,6 +274,14 @@ class TestInventory(unittest.TestCase): print "EXPECTED=%s" % sorted(expected_hosts) assert sorted(hosts) == sorted(expected_hosts) + def test_regex_grouping(self): + inventory = self.simple_inventory() + hosts = inventory.list_hosts("~(cer[a-z]|berc)(erus00[13])") + expected_hosts = ['cerberus001', 'cerberus003'] + print "HOSTS=%s" % sorted(hosts) + print "EXPECTED=%s" % sorted(expected_hosts) + assert sorted(hosts) == sorted(expected_hosts) + def test_complex_enumeration(self):