Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zeitounator/6168991050065ca2c371e99d8d91a2d6 to your computer and use it in GitHub Desktop.
Save zeitounator/6168991050065ca2c371e99d8d91a2d6 to your computer and use it in GitHub Desktop.
$ cat inventory
---
all:
children:
my_poc_hosts:
hosts:
target1:
target2:
target3:
# Undefined for hosts if no user given
$ $ ansible -i inventory all -m debug -a var=ansible_user
target1 | SUCCESS => {
"ansible_user": "VARIABLE IS NOT DEFINED!"
}
target2 | SUCCESS => {
"ansible_user": "VARIABLE IS NOT DEFINED!"
}
target3 | SUCCESS => {
"ansible_user": "VARIABLE IS NOT DEFINED!"
}
# Defined by default for locahost on local connection
$ ansible -i inventory localhost -m debug -a var=ansible_user
localhost | SUCCESS => {
"ansible_user": "my_user_obfuscated"
}
# Defined for hosts if given on command line
$ ansible -i inventory all -u toto -m debug -a var=ansible_user
target1 | SUCCESS => {
"ansible_user": "toto"
}
target2 | SUCCESS => {
"ansible_user": "toto"
}
target3 | SUCCESS => {
"ansible_user": "toto"
}
# .... and ok also with ask-pass ask-sudo-pass
$ ansible -i inventory all -kKu toto -m debug -a var=ansible_user
SSH password:
BECOME password[defaults to SSH password]:
target1 | SUCCESS => {
"ansible_user": "toto"
}
target2 | SUCCESS => {
"ansible_user": "toto"
}
target3 | SUCCESS => {
"ansible_user": "toto"
}
# Does not change for local connection even if you specify a different one
# Defined by default for locahost on local connection
$ ansible -i inventory localhost -m debug -u toto -a var=ansible_user
localhost | SUCCESS => {
"ansible_user": "my_user_obfuscated"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment