From 1733d434d1a151f2a641924d5ae59d3086397117 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 5f9cccae4c..1417bc9d2c 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 6b19f4c172..409f9661b8 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: