Replace ansible_user with ansible_user_id var #201
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR changes
ansible_user
toansible_user_id
.The `ansible_user' variable is used in the inventory to specify which user should be used to log in to the remote host. However, this variable may be missing if the current username is to be used for authentication on the remote system.
There is another special variable that is better suited to get the effective username:
ansible_user_id
. There are 3 login cases that I could identify. Theansible_user_id
variable behaves as follows:elastic
:ansible_user_id
is set toelastic
root
):ansible_user_id
is set to the name of the privileged user (e.g.root
)user1
) but with sudo permissions:ansible_user_id
is set toroot
The following playbook demonstrates this case best:
SSH password:
BECOME password[defaults to SSH password]:
PLAY [all] ***************************************************************************************************************************************
TASK [Gathering Facts] ***************************************************************************************************************************************
ok: [host2]
TASK [debug] ***************************************************************************************************************************************
ok: [host2] => {
"ansible_user": "VARIABLE IS NOT DEFINED!",
"failed_when_result": false
}
TASK [debug] ***************************************************************************************************************************************
ok: [host2] => {
"ansible_user_id": "root",
"failed_when_result": false
}
PLAY RECAP ***************************************************************************************************************************************
host2 : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0