restore hostpattern regex/glob behaviour

they are back to matching both groups and hosts when they are a glob/regex

fixes #32906

(cherry picked from commit e50f931cf3)
This commit is contained in:
Brian Coca 2017-11-21 14:36:05 -05:00
parent b911186024
commit 689065924a
2 changed files with 6 additions and 2 deletions

View file

@ -190,6 +190,8 @@ Ansible Changes By Release
https://github.com/ansible/ansible/pull/33165 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 * 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 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
<a id="2.4.1"></a> <a id="2.4.1"></a>

View file

@ -99,7 +99,7 @@ def split_host_pattern(pattern):
try: try:
(base, port) = parse_address(pattern, allow_ranges=True) (base, port) = parse_address(pattern, allow_ranges=True)
patterns = [pattern] patterns = [pattern]
except: except Exception:
# The only other case we accept is a ':'-separated list of patterns. # The only other case we accept is a ':'-separated list of patterns.
# This mishandles IPv6 addresses, and is retained only for backwards # This mishandles IPv6 addresses, and is retained only for backwards
# compatibility. # compatibility.
@ -524,7 +524,9 @@ class InventoryManager(object):
if matching_groups: if matching_groups:
for groupname in matching_groups: for groupname in matching_groups:
results.extend(self._inventory.groups[groupname].get_hosts()) 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 # pattern might match host
matching_hosts = self._match_list(self._inventory.hosts, pattern) matching_hosts = self._match_list(self._inventory.hosts, pattern)
if matching_hosts: if matching_hosts: