# how to run yum ad-hoc command as different user?

**URL:** <https://forum.ansible.com/t/how-to-run-yum-ad-hoc-command-as-different-user/27988>\
**Category:** Ansible Project\
**Created:** [July 9, 2018, 2:28am UTC](https://forum.ansible.com/t/how-to-run-yum-ad-hoc-command-as-different-user/27988 "2018-07-09T02:28:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vamsee\_Chowdary](https://avatars.discourse-cdn.com/v4/letter/v/eb8c5e/32.png) [@Vamsee\_Chowdary](https://forum.ansible.com/u/Vamsee_Chowdary)\
**Post date:** [July 9, 2018, 2:28am UTC](https://forum.ansible.com/t/how-to-run-yum-ad-hoc-command-as-different-user/27988/1 "2018-07-09T02:28:47Z")

</div>

Hello there,

As a user “vamsi”,i am trying to install httpd on node1 machine using ad-hoc command “yum” from the command line.

please note that user vamsi has sudo privileges on node1.

I tried everything (–become,–ask-become-pass,–become-user) and nothing works.It always gives me the error- You need to be root to perform this command.Below is my code.

[vamsi@controller playbooks]$ ansible node1 -m yum -a “name=httpd state=present” -u vamsi --ask-become-pass  
SUDO password:  
node1 | FAILED! =\> {  
“changed”: false,  
“msg”: “You need to be root to perform this command.\n”,  
“rc”: 1,  
“results”: [  
“Loaded plugins: fastestmirror, langpacks\n”  
]  
}

Appreciate your help,please.  
Thanks,  
Vamsi

---

<div class="post-metadata">

**Author:** ![Benny\_Kusman](https://avatars.discourse-cdn.com/v4/letter/b/4da419/32.png) [@Benny\_Kusman](https://forum.ansible.com/u/Benny_Kusman)\
**Post date:** [July 9, 2018, 2:53am UTC](https://forum.ansible.com/t/how-to-run-yum-ad-hoc-command-as-different-user/27988/2 "2018-07-09T02:53:35Z")

</div>

Hi Vamsi,

try this command:

ansible node1 -m yum -a “name=httpd state=present” -u vamsi --ask-become-pass -b --become-method=sudo

---

<div class="post-metadata">

**Author:** ![Vamsee\_Chowdary](https://avatars.discourse-cdn.com/v4/letter/v/eb8c5e/32.png) [@Vamsee\_Chowdary](https://forum.ansible.com/u/Vamsee_Chowdary)\
**Post date:** [July 9, 2018, 3:17am UTC](https://forum.ansible.com/t/how-to-run-yum-ad-hoc-command-as-different-user/27988/3 "2018-07-09T03:17:45Z")

</div>

Hi Benny

That worked like a charm.You made my day.Thank you very much.
