diff --git a/lib/ansible/playbook/play_context.py b/lib/ansible/playbook/play_context.py index f1fa685503..c77f0ff405 100644 --- a/lib/ansible/playbook/play_context.py +++ b/lib/ansible/playbook/play_context.py @@ -443,7 +443,7 @@ class PlayContext(Base): # additionally, we need to do this check after final connection has been # correctly set above ... if new_info.connection == 'local': - new_info.connection_user = self.remote_user + new_info.connection_user = new_info.remote_user new_info.remote_user = pwd.getpwuid(os.getuid()).pw_name # set no_log to default if it was not previouslly set @@ -597,6 +597,10 @@ class PlayContext(Base): if 'become' in prop: continue + # perserves the user var for local connections + if self.connection == 'local' and 'remote_user' in prop: + continue + var_val = getattr(self, prop) for var_opt in var_list: if var_opt not in variables and var_val is not None: