diff options
author | James Cammarata <jimi@sngx.net> | 2016-07-04 11:05:56 -0500 |
---|---|---|
committer | James Cammarata <jimi@sngx.net> | 2016-07-04 11:25:53 -0500 |
commit | 83e4a4048bbb79538543012fbd6cb520e9a871f4 (patch) | |
tree | 345513fb18512182eb46e7bc207b570358df58e7 | |
parent | 1f04130c00b21b58a6a7f663f8fe22a6f22b2f82 (diff) | |
download | ansible-83e4a4048bbb79538543012fbd6cb520e9a871f4.tar.gz |
Fix the way pull localhosts out of inventory for delegate_to
This patch corrects the way we look in the inventory hosts list for
implicit localhost entries when localhost aliases are used.
Fixes #16568
-rw-r--r-- | lib/ansible/vars/__init__.py | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/lib/ansible/vars/__init__.py b/lib/ansible/vars/__init__.py index 30068d12ad..4100fda1ca 100644 --- a/lib/ansible/vars/__init__.py +++ b/lib/ansible/vars/__init__.py @@ -489,15 +489,18 @@ class VariableManager: # try looking it up based on the address field, and finally # fall back to creating a host on the fly to use for the var lookup if delegated_host is None: - for h in self._inventory.get_hosts(ignore_limits_and_restrictions=True): - # check if the address matches, or if both the delegated_to host - # and the current host are in the list of localhost aliases - if h.address == delegated_host_name or h.name in C.LOCALHOST and delegated_host_name in C.LOCALHOST: - delegated_host = h - break + if delegated_host_name in C.LOCALHOST: + delegated_host = self._inventory.localhost else: - delegated_host = Host(name=delegated_host_name) - delegated_host.vars.update(new_delegated_host_vars) + for h in self._inventory.get_hosts(ignore_limits_and_restrictions=True): + # check if the address matches, or if both the delegated_to host + # and the current host are in the list of localhost aliases + if h.address == delegated_host_name: + delegated_host = h + break + else: + delegated_host = Host(name=delegated_host_name) + delegated_host.vars.update(new_delegated_host_vars) else: delegated_host = Host(name=delegated_host_name) delegated_host.vars.update(new_delegated_host_vars) |