# issue: ansible ad-hoc command -u root and -u oracle with -a id giving same output

**URL:** <https://forum.ansible.com/t/issue-ansible-ad-hoc-command-u-root-and-u-oracle-with-a-id-giving-same-output/30171>\
**Category:** Ansible Developer\
**Created:** [April 23, 2019, 5:55pm UTC](https://forum.ansible.com/t/issue-ansible-ad-hoc-command-u-root-and-u-oracle-with-a-id-giving-same-output/30171 "2019-04-23T17:55:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Naren1](https://avatars.discourse-cdn.com/v4/letter/n/a4c791/32.png) [@Naren1](https://forum.ansible.com/u/Naren1)\
**Post date:** [April 23, 2019, 5:55pm UTC](https://forum.ansible.com/t/issue-ansible-ad-hoc-command-u-root-and-u-oracle-with-a-id-giving-same-output/30171/1 "2019-04-23T17:55:43Z")

</div>

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)

$

 ![ansible_id.PNG](https://us1.discourse-cdn.com/ansible/original/2X/b/bf9f5af395ceee13d301c7a2b9d64d310038bbd7.png)

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [April 23, 2019, 6:19pm UTC](https://forum.ansible.com/t/issue-ansible-ad-hoc-command-u-root-and-u-oracle-with-a-id-giving-same-output/30171/2 "2019-04-23T18:19:28Z")

</div>

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](https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable)

> **(attachments)**
>
> ![ansible_id.PNG](https://us1.discourse-cdn.com/ansible/original/2X/b/bf9f5af395ceee13d301c7a2b9d64d310038bbd7.png)

---

<div class="post-metadata">

**Author:** ![Naren1](https://avatars.discourse-cdn.com/v4/letter/n/a4c791/32.png) [@Naren1](https://forum.ansible.com/u/Naren1)\
**Post date:** [April 23, 2019, 11:51pm UTC](https://forum.ansible.com/t/issue-ansible-ad-hoc-command-u-root-and-u-oracle-with-a-id-giving-same-output/30171/3 "2019-04-23T23:51:02Z")

</div>

Thanks so much, it worked

however, still having issue with a specific group, let me re-review and see…

Thanks again and Regards,Naren

---

<div class="post-metadata">

**Author:** ![Naren1](https://avatars.discourse-cdn.com/v4/letter/n/a4c791/32.png) [@Naren1](https://forum.ansible.com/u/Naren1)\
**Post date:** [April 24, 2019, 12:09am UTC](https://forum.ansible.com/t/issue-ansible-ad-hoc-command-u-root-and-u-oracle-with-a-id-giving-same-output/30171/4 "2019-04-24T00:09:33Z")

</div>

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

1. ansible -i test.ini db -m shell -a ‘id;pwd;ls;hostname’

2. ansible -i test.ini mt -m shell -a ‘id;pwd;ls;hostname’

3. 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

---

<div class="post-metadata">

**Author:** ![Naren1](https://avatars.discourse-cdn.com/v4/letter/n/a4c791/32.png) [@Naren1](https://forum.ansible.com/u/Naren1)\
**Post date:** [April 24, 2019, 12:22am UTC](https://forum.ansible.com/t/issue-ansible-ad-hoc-command-u-root-and-u-oracle-with-a-id-giving-same-output/30171/5 "2019-04-24T00:22:35Z")

</div>

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

1. ansible -i test.ini db -m shell -a ‘id;pwd;ls;hostname’

2. ansible -i test.ini mt -m shell -a ‘id;pwd;ls;hostname’

3. ansible -i test.ini root -m shell -a ‘id;pwd;ls;hostname’

---

<div class="post-metadata">

**Author:** ![cassell](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@cassell](https://forum.ansible.com/u/cassell)\
**Post date:** [April 24, 2019, 1:53am UTC](https://forum.ansible.com/t/issue-ansible-ad-hoc-command-u-root-and-u-oracle-with-a-id-giving-same-output/30171/6 "2019-04-24T01:53:31Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![Naren1](https://avatars.discourse-cdn.com/v4/letter/n/a4c791/32.png) [@Naren1](https://forum.ansible.com/u/Naren1)\
**Post date:** [April 24, 2019, 11:26am UTC](https://forum.ansible.com/t/issue-ansible-ad-hoc-command-u-root-and-u-oracle-with-a-id-giving-same-output/30171/7 "2019-04-24T11:26:57Z")

</div>

Great, thank you for the explanation and the solution…

Thanks again and Regards,  
Naren
