From 2dfcb218dcf96a717115ba777bc8724da5980258 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Mon, 18 Jan 2016 17:32:25 -0500 Subject: [PATCH] Fix with loop + delegate issues * Don't re-use the existing connection if the remote_addr field of the play context has changed * When overriding variables in PlayContext (from task/variables), don't set the same attribute based on a different variable name if we had already previously set it from another variable name Fixes #13880 --- lib/ansible/executor/task_executor.py | 2 +- lib/ansible/playbook/play_context.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index 5747991f831..c42de427fc9 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -367,7 +367,7 @@ class TaskExecutor: self._task.args = variable_params # get the connection and the handler for this execution - if not self._connection or not getattr(self._connection, 'connected', False): + 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) else: diff --git a/lib/ansible/playbook/play_context.py b/lib/ansible/playbook/play_context.py index 89beeaddbc4..78a86ff2454 100644 --- a/lib/ansible/playbook/play_context.py +++ b/lib/ansible/playbook/play_context.py @@ -366,12 +366,17 @@ class PlayContext(Base): else: delegated_vars = dict() + attrs_considered = [] for (attr, variable_names) in iteritems(MAGIC_VARIABLE_MAPPING): for variable_name in variable_names: + if attr in attrs_considered: + continue if isinstance(delegated_vars, dict) and variable_name in delegated_vars: setattr(new_info, attr, delegated_vars[variable_name]) + attrs_considered.append(attr) elif variable_name in variables: setattr(new_info, attr, variables[variable_name]) + attrs_considered.append(attr) # make sure we get port defaults if needed if new_info.port is None and C.DEFAULT_REMOTE_PORT is not None: