mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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
This commit is contained in:
parent
1c9774785f
commit
1733d434d1
2 changed files with 6 additions and 1 deletions
|
@ -367,7 +367,7 @@ class TaskExecutor:
|
||||||
self._task.args = variable_params
|
self._task.args = variable_params
|
||||||
|
|
||||||
# get the connection and the handler for this execution
|
# 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 = self._get_connection(variables=variables, templar=templar)
|
||||||
self._connection.set_host_overrides(host=self._host)
|
self._connection.set_host_overrides(host=self._host)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -366,12 +366,17 @@ class PlayContext(Base):
|
||||||
else:
|
else:
|
||||||
delegated_vars = dict()
|
delegated_vars = dict()
|
||||||
|
|
||||||
|
attrs_considered = []
|
||||||
for (attr, variable_names) in iteritems(MAGIC_VARIABLE_MAPPING):
|
for (attr, variable_names) in iteritems(MAGIC_VARIABLE_MAPPING):
|
||||||
for variable_name in variable_names:
|
for variable_name in variable_names:
|
||||||
|
if attr in attrs_considered:
|
||||||
|
continue
|
||||||
if isinstance(delegated_vars, dict) and variable_name in delegated_vars:
|
if isinstance(delegated_vars, dict) and variable_name in delegated_vars:
|
||||||
setattr(new_info, attr, delegated_vars[variable_name])
|
setattr(new_info, attr, delegated_vars[variable_name])
|
||||||
|
attrs_considered.append(attr)
|
||||||
elif variable_name in variables:
|
elif variable_name in variables:
|
||||||
setattr(new_info, attr, variables[variable_name])
|
setattr(new_info, attr, variables[variable_name])
|
||||||
|
attrs_considered.append(attr)
|
||||||
|
|
||||||
# make sure we get port defaults if needed
|
# make sure we get port defaults if needed
|
||||||
if new_info.port is None and C.DEFAULT_REMOTE_PORT is not None:
|
if new_info.port is None and C.DEFAULT_REMOTE_PORT is not None:
|
||||||
|
|
Loading…
Reference in a new issue