mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-26 12:21:26 -07:00
properly track delegated host in loops
ansible_host can be pulled from inventory and not match inventory_hostname, this can "loose" vars to a new host named by ansible_host vs the delegated host fixes #25770
This commit is contained in:
parent
b6ee9163e3
commit
9d8721dbde
3 changed files with 4 additions and 3 deletions
|
@ -628,7 +628,7 @@ class TaskExecutor:
|
||||||
delegated_vars = variables.get('ansible_delegated_vars', dict()).get(self._task.delegate_to, dict()).copy()
|
delegated_vars = variables.get('ansible_delegated_vars', dict()).get(self._task.delegate_to, dict()).copy()
|
||||||
if len(delegated_vars) > 0:
|
if len(delegated_vars) > 0:
|
||||||
result["_ansible_delegated_vars"] = dict()
|
result["_ansible_delegated_vars"] = dict()
|
||||||
for k in ('ansible_host', ):
|
for k in ('ansible_delegated_host', 'ansible_host' ):
|
||||||
result["_ansible_delegated_vars"][k] = delegated_vars.get(k)
|
result["_ansible_delegated_vars"][k] = delegated_vars.get(k)
|
||||||
|
|
||||||
# and return
|
# and return
|
||||||
|
|
|
@ -245,7 +245,7 @@ class StrategyBase:
|
||||||
return host_list
|
return host_list
|
||||||
|
|
||||||
def get_delegated_hosts(self, result, task):
|
def get_delegated_hosts(self, result, task):
|
||||||
host_name = result.get('_ansible_delegated_vars', {}).get('ansible_host', None)
|
host_name = result.get('_ansible_delegated_vars', {}).get('ansible_delegated_host', None)
|
||||||
if host_name is not None:
|
if host_name is not None:
|
||||||
actual_host = self._inventory.get_host(host_name)
|
actual_host = self._inventory.get_host(host_name)
|
||||||
if actual_host is None:
|
if actual_host is None:
|
||||||
|
|
|
@ -524,7 +524,8 @@ class VariableManager:
|
||||||
new_port = 5986
|
new_port = 5986
|
||||||
|
|
||||||
new_delegated_host_vars = dict(
|
new_delegated_host_vars = dict(
|
||||||
ansible_host=delegated_host_name,
|
ansible_delegated_host=delegated_host_name,
|
||||||
|
ansible_host=delegated_host_name, # not redundant as other sources can change ansible_host
|
||||||
ansible_port=new_port,
|
ansible_port=new_port,
|
||||||
ansible_user=C.DEFAULT_REMOTE_USER,
|
ansible_user=C.DEFAULT_REMOTE_USER,
|
||||||
ansible_connection=C.DEFAULT_TRANSPORT,
|
ansible_connection=C.DEFAULT_TRANSPORT,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue