* Use inventory.get_host instead of direct access to inventory.hosts (#41860)
* Use inventory.get_host instead of direct access to inventory.hosts. Fixes #32152
* Prevent potential side effect, by using self._inventory.localhost directly instead of get_host
(cherry picked from commit 1a2ef0922f
)
* Add changelog for #41860
This commit is contained in:
parent
9757233a93
commit
916317466d
2 changed files with 8 additions and 1 deletions
2
changelogs/fragments/group_by_localhost.yaml
Normal file
2
changelogs/fragments/group_by_localhost.yaml
Normal file
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- group_by - support implicit localhost (https://github.com/ansible/ansible/pull/41860)
|
|
@ -717,7 +717,12 @@ class StrategyBase:
|
|||
# the host here is from the executor side, which means it was a
|
||||
# serialized/cloned copy and we'll need to look up the proper
|
||||
# host object from the master inventory
|
||||
real_host = self._inventory.hosts[host.name]
|
||||
real_host = self._inventory.hosts.get(host.name)
|
||||
if real_host is None:
|
||||
if host.name == self._inventory.localhost.name:
|
||||
real_host = self._inventory.localhost
|
||||
else:
|
||||
raise AnsibleError('%s cannot be matched in inventory' % host.name)
|
||||
group_name = result_item.get('add_group')
|
||||
parent_group_names = result_item.get('parent_groups', [])
|
||||
|
||||
|
|
Loading…
Reference in a new issue