summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Coca <brian.coca+git@gmail.com>2017-06-19 17:03:28 -0400
committerBrian Coca <bcoca@users.noreply.github.com>2017-06-19 17:50:52 -0400
commit9d8721dbdee25aef0c87daab4c6d4bf8b749ce1d (patch)
treec2e0c3de4284e1c0901b6a07a9545338359e899f
parentb6ee9163e340cd47d8adffe331576b0b37f740a5 (diff)
downloadansible-9d8721dbdee25aef0c87daab4c6d4bf8b749ce1d.tar.gz
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
-rw-r--r--lib/ansible/executor/task_executor.py2
-rw-r--r--lib/ansible/plugins/strategy/__init__.py2
-rw-r--r--lib/ansible/vars/manager.py3
3 files changed, 4 insertions, 3 deletions
diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py
index ecdac5ee40..85e334b9a6 100644
--- a/lib/ansible/executor/task_executor.py
+++ b/lib/ansible/executor/task_executor.py
@@ -628,7 +628,7 @@ class TaskExecutor:
delegated_vars = variables.get('ansible_delegated_vars', dict()).get(self._task.delegate_to, dict()).copy()
if len(delegated_vars) > 0:
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)
# and return
diff --git a/lib/ansible/plugins/strategy/__init__.py b/lib/ansible/plugins/strategy/__init__.py
index 2b10f87b7a..8cb918f50a 100644
--- a/lib/ansible/plugins/strategy/__init__.py
+++ b/lib/ansible/plugins/strategy/__init__.py
@@ -245,7 +245,7 @@ class StrategyBase:
return host_list
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:
actual_host = self._inventory.get_host(host_name)
if actual_host is None:
diff --git a/lib/ansible/vars/manager.py b/lib/ansible/vars/manager.py
index 6747dff377..7dd4e205b0 100644
--- a/lib/ansible/vars/manager.py
+++ b/lib/ansible/vars/manager.py
@@ -524,7 +524,8 @@ class VariableManager:
new_port = 5986
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_user=C.DEFAULT_REMOTE_USER,
ansible_connection=C.DEFAULT_TRANSPORT,