Naren1
(Naren)
April 23, 2019, 5:55pm
1
I am expecting “id” command to show the user details passed to “-u <user name”
“id” command to return details of root, oracle, and applmgr users on each run
but in below output is showing only one user for all, why ?
$ ansible -i hosts.ini db -u root -m shell -a id
host1 | SUCCESS | rc=0 >>
uid=500(oracle) gid=500(dba) groups=500(dba)
$ ansible -i hosts.ini db -u oracle -m shell -a id
host1 | SUCCESS | rc=0 >>
uid=500(oracle) gid=500(dba) groups=500(dba)
$ ansible -i hosts.ini db -u applmgr -m shell -a id
host1 | SUCCESS | rc=0 >>
uid=500(oracle) gid=500(dba) groups=500(dba)
$
sivel
(sivel)
April 23, 2019, 6:19pm
2
Do you have ansible_user
defined in your hosts.ini
file? If so, the inventory var will win over the CLI value. See https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable
(attachments)
Naren1
(Naren)
April 23, 2019, 11:51pm
3
Thanks so much, it worked
however, still having issue with a specific group, let me re-review and see…
Thanks again and Regards,Naren
Naren1
(Naren)
April 24, 2019, 12:09am
4
Provided my inventory file at the end
Below 3 commands are returning same output, that is, “applmgr” user’s information rather than their corresponding “ansible_user” info
ansible -i test.ini db -m shell -a ‘id;pwd;ls;hostname’
ansible -i test.ini mt -m shell -a ‘id;pwd;ls;hostname’
ansible -i test.ini root -m shell -a ‘id;pwd;ls;hostname’
please see, what am i missing here ?
Below is my inventory file :
$ cat test.ini
[db]
host1 ansible_user=oracle
[root]
host1 ansible_user=root
[mt]
host1 ansible_user=applmgr
Naren1
(Naren)
April 24, 2019, 12:22am
5
Continuation to previous updated issue…
What I observed is - ansible is always picking “last” group in the test.ini file
I have changed the order of groups, below is the complete contents of .ini file
$ cat test.ini
[root]
host1 ansible_user=root
[mt]
host1 ansible_user=applmgr
[db]
host1 ansible_user=oracle
all 3 commands show “oracle” user’s information rather than their corresponding user’s info
ansible -i test.ini db -m shell -a ‘id;pwd;ls;hostname’
ansible -i test.ini mt -m shell -a ‘id;pwd;ls;hostname’
ansible -i test.ini root -m shell -a ‘id;pwd;ls;hostname’
cassell
(James Cassell)
April 24, 2019, 1:53am
6
Continuation to previous updated issue...
What I observed is - ansible is always picking "last" group in the test.ini
file
If a single host is in multiple groups, the last definition of a variable wins. When you specify a group to target, ansible internally converts it to a list of hosts. Once any groups have been resolved to hosts, ansible has no concept of which group any host was requested from.
I have changed the order of groups, below is the complete contents of .ini
file
$ cat test.ini
[root]
host1 ansible_user=root
root-host1 ansible_host=host1 ansible_user=root
[mt]
host1 ansible_user=applmgr
mt-host1 ansible_host=host1 ansible_user=applmgr
[db]
host1 ansible_user=oracle
Etc.
You could use such a workaround.
V/r,
James Cassell
Naren1
(Naren)
April 24, 2019, 11:26am
7
Great, thank you for the explanation and the solution…
Thanks again and Regards,
Naren