From 58ee661437f123fdd8cf516bac053fe593910ced Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Wed, 22 Feb 2017 10:34:11 -0500 Subject: [PATCH] fixes play context connection user (#21776) Does't map remote_user back into vars if connection is local to preserve the user variable. This is done to be able to set connection_user prop in play_context for the network_cli plugin connection --- lib/ansible/playbook/play_context.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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: