summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Davis <nitzmahone@users.noreply.github.com>2017-04-20 20:33:48 -0700
committerMatt Davis <mdavis@ansible.com>2017-04-20 20:34:32 -0700
commita021b4bd8b7b76fea69642369a8ca7b41ec9a7c6 (patch)
tree92a718286e0d5cbcff22e0d1cc70d4e855c49446
parentc05aa9373917f3b222768dcda75607a22446078d (diff)
downloadansible-a021b4bd8b7b76fea69642369a8ca7b41ec9a7c6.tar.gz
template hostvars for set_host_overrides (#23839)
* fixes #23586 * temporary solution until connection-specific vars are handled by play_context (cherry picked from commit 02ed223d49d806b3446ba2dfedd4d453c8e79603)
-rw-r--r--lib/ansible/executor/task_executor.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py
index b1974b923e..6f9fb4d451 100644
--- a/lib/ansible/executor/task_executor.py
+++ b/lib/ansible/executor/task_executor.py
@@ -32,6 +32,7 @@ from ansible.executor.task_result import TaskResult
from ansible.module_utils._text import to_text
from ansible.playbook.conditional import Conditional
from ansible.playbook.task import Task
+from ansible.plugins.connection import ConnectionBase
from ansible.template import Templar
from ansible.utils.encrypt import key_for_hostname
from ansible.utils.listify import listify_lookup_plugin_terms
@@ -471,16 +472,17 @@ class TaskExecutor:
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)
hostvars = variables.get('hostvars', None)
- if hostvars:
+ # only template the vars if the connection actually implements set_host_overrides
+ # NB: this is expensive, and should be removed once connection-specific vars are being handled by play_context
+ sho_impl = getattr(type(self._connection), 'set_host_overrides', None)
+ if hostvars and sho_impl and sho_impl != ConnectionBase.set_host_overrides:
try:
- target_hostvars = hostvars.raw_get(self._host.name)
+ target_hostvars = hostvars.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)
+ 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