1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Also make sure remote_user is defaulted correctly for delegated hosts

Fixes #13323
This commit is contained in:
James Cammarata 2015-11-30 16:14:40 -05:00
parent e2ddc2f6ab
commit dc0fae1af7
2 changed files with 10 additions and 0 deletions

View file

@ -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) 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 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'): for port_var in MAGIC_VARIABLE_MAPPING.get('port'):
if port_var in delegated_vars: if port_var in delegated_vars:
break break
@ -342,6 +344,13 @@ class PlayContext(Base):
delegated_vars['ansible_port'] = 5986 delegated_vars['ansible_port'] = 5986
else: else:
delegated_vars['ansible_port'] = C.DEFAULT_REMOTE_PORT 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: else:
delegated_vars = dict() delegated_vars = dict()

View file

@ -91,6 +91,7 @@ class TestPlayContext(unittest.TestCase):
mock_task.become_user = 'mocktaskroot' mock_task.become_user = 'mocktaskroot'
mock_task.become_pass = 'mocktaskpass' mock_task.become_pass = 'mocktaskpass'
mock_task._local_action = False mock_task._local_action = False
mock_task.delegate_to = None
all_vars = dict( all_vars = dict(
ansible_connection = 'mock_inventory', ansible_connection = 'mock_inventory',