From e50f931cf3284879e0ed2abcef154a848777ff12 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Tue, 21 Nov 2017 14:36:05 -0500 Subject: [PATCH] restore hostpattern regex/glob behaviour they are back to matching both groups and hosts when they are a glob/regex fixes #32906 --- lib/ansible/inventory/manager.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/ansible/inventory/manager.py b/lib/ansible/inventory/manager.py index caac03a68dd..cf257f09825 100644 --- a/lib/ansible/inventory/manager.py +++ b/lib/ansible/inventory/manager.py @@ -99,7 +99,7 @@ def split_host_pattern(pattern): try: (base, port) = parse_address(pattern, allow_ranges=True) patterns = [pattern] - except: + except Exception: # The only other case we accept is a ':'-separated list of patterns. # This mishandles IPv6 addresses, and is retained only for backwards # compatibility. @@ -526,7 +526,9 @@ class InventoryManager(object): if matching_groups: for groupname in matching_groups: results.extend(self._inventory.groups[groupname].get_hosts()) - else: + + # check hosts if no groups matched or it is a regex/glob pattern + if not matching_groups or pattern.startswith('~') or any(special in pattern for special in ('.', '?', '*', '[')): # pattern might match host matching_hosts = self._match_list(self._inventory.hosts, pattern) if matching_hosts: