summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Cammarata <jimi@sngx.net>2015-08-27 12:54:23 -0400
committerJames Cammarata <jimi@sngx.net>2015-08-27 12:54:23 -0400
commit1170a453c8cfb518eb4ae6e95fa1bfa4b9345cc2 (patch)
treebd6c12b0f25ef03801138eed1b31a4b95ac8c236
parentef594f708c6eca9ad45d4926b942cf6ce0f15ee1 (diff)
parent81bf88b6e052cdf72aef079e551a5a075d6ac85c (diff)
downloadansible-1170a453c8cfb518eb4ae6e95fa1bfa4b9345cc2.tar.gz
Merge pull request #12114 from ilya-epifanov/devel
fixed hostvars access in conjunction with --limit usage
-rw-r--r--lib/ansible/inventory/__init__.py18
-rw-r--r--lib/ansible/vars/hostvars.py2
2 files changed, 11 insertions, 9 deletions
diff --git a/lib/ansible/inventory/__init__.py b/lib/ansible/inventory/__init__.py
index 1bb743287e..a3bb0bba47 100644
--- a/lib/ansible/inventory/__init__.py
+++ b/lib/ansible/inventory/__init__.py
@@ -178,7 +178,7 @@ class Inventory(object):
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
inventory host names, taking into account any active restrictions
@@ -196,14 +196,16 @@ class Inventory(object):
patterns = self._split_pattern(pattern)
hosts = self._evaluate_patterns(patterns)
- # exclude hosts not in a subset, if defined
- if self._subset:
- subset = self._evaluate_patterns(self._subset)
- hosts = [ h for h in hosts if h in subset ]
+ # mainly useful for hostvars[host] access
+ if not ignore_limits_and_restrictions:
+ # exclude hosts not in a subset, if defined
+ if self._subset:
+ subset = self._evaluate_patterns(self._subset)
+ hosts = [ h for h in hosts if h in subset ]
- # exclude hosts mentioned in any restriction (ex: failed hosts)
- if self._restriction is not None:
- hosts = [ h for h in hosts if h in self._restriction ]
+ # exclude hosts mentioned in any restriction (ex: failed hosts)
+ if self._restriction is not None:
+ hosts = [ h for h in hosts if h in self._restriction ]
return hosts
diff --git a/lib/ansible/vars/hostvars.py b/lib/ansible/vars/hostvars.py
index 39c6dfa26a..1a77d9edbe 100644
--- a/lib/ansible/vars/hostvars.py
+++ b/lib/ansible/vars/hostvars.py
@@ -43,7 +43,7 @@ class HostVars(collections.Mapping):
# in inventory
restriction = inventory._restriction
inventory.remove_restriction()
- hosts = inventory.get_hosts()
+ hosts = inventory.get_hosts(ignore_limits_and_restrictions=True)
inventory.restrict_to_hosts(restriction)
# check to see if localhost is in the hosts list, as we