mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 21:32:49 +00:00
Create a raw lookup for hostvars that does not template the data
When using hostvars to get extra connection-specific vars for connection plugins, use this raw lookup to avoid prematurely templating all of the hostvar data (triggering unnecessary lookups). Fixes #17024
This commit is contained in:
@@ -437,7 +437,17 @@ class TaskExecutor:
|
||||
# get the connection and the handler for this execution
|
||||
if not self._connection or not getattr(self._connection, 'connected', False) or self._play_context.remote_addr != self._connection._play_context.remote_addr:
|
||||
self._connection = self._get_connection(variables=variables, templar=templar)
|
||||
self._connection.set_host_overrides(host=self._host, hostvars=variables.get('hostvars', {}).get(self._host.name, {}))
|
||||
hostvars = variables.get('hostvars', None)
|
||||
if hostvars:
|
||||
try:
|
||||
target_hostvars = hostvars.raw_get(self._host.name)
|
||||
except:
|
||||
# FIXME: this should catch the j2undefined error here
|
||||
# specifically instead of all exceptions
|
||||
target_hostvars = dict()
|
||||
else:
|
||||
target_hostvars = dict()
|
||||
self._connection.set_host_overrides(host=self._host, hostvars=target_hostvars)
|
||||
else:
|
||||
# if connection is reused, its _play_context is no longer valid and needs
|
||||
# to be replaced with the one templated above, in case other data changed
|
||||
|
||||
Reference in New Issue
Block a user