From dc0fae1af76821ab6fb741cd3e9da285a9d815a2 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Mon, 30 Nov 2015 16:14:40 -0500 Subject: [PATCH] Also make sure remote_user is defaulted correctly for delegated hosts Fixes #13323 --- lib/ansible/playbook/play_context.py | 9 +++++++++ test/units/playbook/test_play_context.py | 1 + 2 files changed, 10 insertions(+) diff --git a/lib/ansible/playbook/play_context.py b/lib/ansible/playbook/play_context.py index 8edaa12a03..b2b7e44497 100644 --- a/lib/ansible/playbook/play_context.py +++ b/lib/ansible/playbook/play_context.py @@ -334,6 +334,8 @@ class PlayContext(Base): display.debug("no remote address found for delegated host %s\nusing its name, so success depends on DNS resolution" % delegated_host_name) delegated_vars['ansible_host'] = delegated_host_name + # reset the port back to the default if none was specified, to prevent + # the delegated host from inheriting the original host's setting for port_var in MAGIC_VARIABLE_MAPPING.get('port'): if port_var in delegated_vars: break @@ -342,6 +344,13 @@ class PlayContext(Base): delegated_vars['ansible_port'] = 5986 else: delegated_vars['ansible_port'] = C.DEFAULT_REMOTE_PORT + + # and likewise for the remote user + for user_var in MAGIC_VARIABLE_MAPPING.get('remote_user'): + if user_var in delegated_vars: + break + else: + delegated_vars['ansible_user'] = None else: delegated_vars = dict() diff --git a/test/units/playbook/test_play_context.py b/test/units/playbook/test_play_context.py index 0595966f1b..5434ef3000 100644 --- a/test/units/playbook/test_play_context.py +++ b/test/units/playbook/test_play_context.py @@ -91,6 +91,7 @@ class TestPlayContext(unittest.TestCase): mock_task.become_user = 'mocktaskroot' mock_task.become_pass = 'mocktaskpass' mock_task._local_action = False + mock_task.delegate_to = None all_vars = dict( ansible_connection = 'mock_inventory',