mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
correctly map to connection_user from remote_user in play_context (#28676)
This change will map the remote_user prop to connection_user if it is not aleady set. It also adds a var mapping to ansible_connection_user in the inventory to override the local user if needed. This is primarily used by the network_cli connection plugin today. fixes #26120
This commit is contained in:
parent
a7fd806fde
commit
ebf529f8b8
1 changed files with 3 additions and 2 deletions
|
@ -75,6 +75,7 @@ MAGIC_VARIABLE_MAPPING = dict(
|
||||||
|
|
||||||
# networking modules
|
# networking modules
|
||||||
network_os=('ansible_network_os', ),
|
network_os=('ansible_network_os', ),
|
||||||
|
connection_user=('ansible_connection_user',),
|
||||||
|
|
||||||
# ssh TODO: remove
|
# ssh TODO: remove
|
||||||
ssh_executable=('ansible_ssh_executable', ),
|
ssh_executable=('ansible_ssh_executable', ),
|
||||||
|
@ -494,9 +495,9 @@ class PlayContext(Base):
|
||||||
# if the final connection type is local, reset the remote_user value to that of the currently logged in user
|
# if the final connection type is local, reset the remote_user value to that of the currently logged in user
|
||||||
# this ensures any become settings are obeyed correctly
|
# this ensures any become settings are obeyed correctly
|
||||||
# we store original in 'connection_user' for use of network/other modules that fallback to it as login user
|
# we store original in 'connection_user' for use of network/other modules that fallback to it as login user
|
||||||
# this needs to be done before the MAGIC_VARIABLE_MAPPING happens
|
|
||||||
if new_info.connection == 'local':
|
if new_info.connection == 'local':
|
||||||
new_info.connection_user = new_info.remote_user
|
if not new_info.connection_user:
|
||||||
|
new_info.connection_user = new_info.remote_user
|
||||||
new_info.remote_user = pwd.getpwuid(os.getuid()).pw_name
|
new_info.remote_user = pwd.getpwuid(os.getuid()).pw_name
|
||||||
|
|
||||||
# set no_log to default if it was not previouslly set
|
# set no_log to default if it was not previouslly set
|
||||||
|
|
Loading…
Reference in a new issue