summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Cassell <james.cassell@ll.mit.edu>2018-06-18 11:10:16 -0400
committerMatt Clay <matt@mystile.com>2018-06-18 15:00:51 -0700
commit5dd90fb752856b802ef9a8e03f44d684b690664d (patch)
tree39b44fc7c907793dfc7bfda7666c01c61df4ced4
parentec87203d4bc8b04ede189a9015b9b70546455e14 (diff)
downloadansible-5dd90fb752856b802ef9a8e03f44d684b690664d.tar.gz
update play_context for reset_connection (#40866)
steps taken from lib/ansible/executor/task_executor.py fixes: https://github.com/ansible/ansible/issues/27520 (cherry picked from commit 23fbe0ce8e942427ed602e90caa744f07f978d6c)
-rw-r--r--changelogs/fragments/reset_con_fix.yml2
-rw-r--r--lib/ansible/plugins/strategy/__init__.py24
2 files changed, 26 insertions, 0 deletions
diff --git a/changelogs/fragments/reset_con_fix.yml b/changelogs/fragments/reset_con_fix.yml
new file mode 100644
index 0000000000..645b3fe2e4
--- /dev/null
+++ b/changelogs/fragments/reset_con_fix.yml
@@ -0,0 +1,2 @@
+bugfixes:
+ - uses correct conn info for reset_connection https://github.com/ansible/ansible/issues/27520
diff --git a/lib/ansible/plugins/strategy/__init__.py b/lib/ansible/plugins/strategy/__init__.py
index e8f6a75edf..32053b4da5 100644
--- a/lib/ansible/plugins/strategy/__init__.py
+++ b/lib/ansible/plugins/strategy/__init__.py
@@ -988,6 +988,30 @@ class StrategyBase:
iterator._host_states[host.name].run_state = iterator.ITERATING_COMPLETE
msg = "ending play"
elif meta_action == 'reset_connection':
+ all_vars = self._variable_manager.get_vars(play=iterator._play, host=target_host, task=task)
+ templar = Templar(loader=self._loader, variables=all_vars)
+
+ # apply the given task's information to the connection info,
+ # which may override some fields already set by the play or
+ # the options specified on the command line
+ play_context = play_context.set_task_and_variable_override(task=task, variables=all_vars, templar=templar)
+
+ # fields set from the play/task may be based on variables, so we have to
+ # do the same kind of post validation step on it here before we use it.
+ play_context.post_validate(templar=templar)
+
+ # now that the play context is finalized, if the remote_addr is not set
+ # default to using the host's address field as the remote address
+ if not play_context.remote_addr:
+ play_context.remote_addr = target_host.address
+
+ # We also add "magic" variables back into the variables dict to make sure
+ # a certain subset of variables exist.
+ play_context.update_vars(all_vars)
+
+ if task.when:
+ self._cond_not_supported_warn(meta_action)
+
if target_host in self._active_connections:
connection = Connection(self._active_connections[target_host])
del self._active_connections[target_host]