diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cfd2f8d8c..cf70e933ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -190,6 +190,8 @@ Ansible Changes By Release https://github.com/ansible/ansible/pull/33165 * Fix for breaking change to Azure Python SDK that prevented some members from being returned in facts modules https://github.com/ansible/ansible/pull/33169 +* restored glob/regex host pattern matching to traverse groups and hosts and not return after first found + https://github.com/ansible/ansible/pull/33158 diff --git a/lib/ansible/inventory/manager.py b/lib/ansible/inventory/manager.py index 916a6c7414..6c25d90ded 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. @@ -524,7 +524,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: