mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
fixed hostvars access in conjunction with --limit usage
This commit is contained in:
parent
0441a7a217
commit
81bf88b6e0
2 changed files with 11 additions and 9 deletions
|
@ -178,7 +178,7 @@ class Inventory(object):
|
||||||
|
|
||||||
return [x for x in term.findall(pattern) if x]
|
return [x for x in term.findall(pattern) if x]
|
||||||
|
|
||||||
def get_hosts(self, pattern="all"):
|
def get_hosts(self, pattern="all", ignore_limits_and_restrictions=False):
|
||||||
"""
|
"""
|
||||||
Takes a pattern or list of patterns and returns a list of matching
|
Takes a pattern or list of patterns and returns a list of matching
|
||||||
inventory host names, taking into account any active restrictions
|
inventory host names, taking into account any active restrictions
|
||||||
|
@ -196,6 +196,8 @@ class Inventory(object):
|
||||||
patterns = self._split_pattern(pattern)
|
patterns = self._split_pattern(pattern)
|
||||||
hosts = self._evaluate_patterns(patterns)
|
hosts = self._evaluate_patterns(patterns)
|
||||||
|
|
||||||
|
# mainly useful for hostvars[host] access
|
||||||
|
if not ignore_limits_and_restrictions:
|
||||||
# exclude hosts not in a subset, if defined
|
# exclude hosts not in a subset, if defined
|
||||||
if self._subset:
|
if self._subset:
|
||||||
subset = self._evaluate_patterns(self._subset)
|
subset = self._evaluate_patterns(self._subset)
|
||||||
|
|
|
@ -43,7 +43,7 @@ class HostVars(collections.Mapping):
|
||||||
# in inventory
|
# in inventory
|
||||||
restriction = inventory._restriction
|
restriction = inventory._restriction
|
||||||
inventory.remove_restriction()
|
inventory.remove_restriction()
|
||||||
hosts = inventory.get_hosts()
|
hosts = inventory.get_hosts(ignore_limits_and_restrictions=True)
|
||||||
inventory.restrict_to_hosts(restriction)
|
inventory.restrict_to_hosts(restriction)
|
||||||
|
|
||||||
# check to see if localhost is in the hosts list, as we
|
# check to see if localhost is in the hosts list, as we
|
||||||
|
|
Loading…
Reference in a new issue