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

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

Hi Vamsi,

try this command:

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

Hi Benny

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