From 292be944c6259af4208f99fedc5c4bb418022da9 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Thu, 17 Mar 2016 08:50:18 -0700 Subject: [PATCH] ensure we use delegated vars on delegation this prevents falling back to connection vars from the inventory_hostname when matching connection var is not in delegated host. --- lib/ansible/playbook/play_context.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/ansible/playbook/play_context.py b/lib/ansible/playbook/play_context.py index 34b9affade6..a48f7395b49 100644 --- a/lib/ansible/playbook/play_context.py +++ b/lib/ansible/playbook/play_context.py @@ -359,12 +359,15 @@ class PlayContext(Base): 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) + # if delegation task ONLY use delegated host vars, avoid delegated FOR host vars + if task.delegate_to is not None: + 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) + # no else, as no other vars should be considered # make sure we get port defaults if needed if new_info.port is None and C.DEFAULT_REMOTE_PORT is not None: