# run command on ansible host with sudo privilege.

**URL:** <https://forum.ansible.com/t/run-command-on-ansible-host-with-sudo-privilege/22796>\
**Category:** Ansible Project\
**Created:** [October 14, 2016, 9:19pm UTC](https://forum.ansible.com/t/run-command-on-ansible-host-with-sudo-privilege/22796 "2016-10-14T21:19:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kevin\_Parent](https://avatars.discourse-cdn.com/v4/letter/k/58956e/32.png) [@Kevin\_Parent](https://forum.ansible.com/u/Kevin_Parent)\
**Post date:** [October 14, 2016, 9:19pm UTC](https://forum.ansible.com/t/run-command-on-ansible-host-with-sudo-privilege/22796/1 "2016-10-14T21:19:14Z")

</div>

Hi guys, I am using:

- hosts: 127.0.0.1  
connection: local

to execute command on the ansible host, I disabled privilege escalation because I would get an error message:

“module\_stderr”: "sudo: effective uid is not 0, is /usr/bin/sudo on a file system with the ‘nosuid’ option set or an NFS file system without root privileges?

Im trying to execute the command: npm install --production. but some of the packages requires sudo permission to be installed

So now what?

:(.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [October 20, 2016, 4:28am UTC](https://forum.ansible.com/t/run-command-on-ansible-host-with-sudo-privilege/22796/2 "2016-10-20T04:28:51Z")

</div>

Can you sudo normally on your machine?

You can also use su or other methods if sudo is not available on your machine, or execute the ansible itself as root.

---

<div class="post-metadata">

**Author:** ![Vipul\_Vadoliya](https://avatars.discourse-cdn.com/v4/letter/v/9f8e36/32.png) [@Vipul\_Vadoliya](https://forum.ansible.com/u/Vipul_Vadoliya)\
**Post date:** [October 20, 2016, 9:02am UTC](https://forum.ansible.com/t/run-command-on-ansible-host-with-sudo-privilege/22796/3 "2016-10-20T09:02:52Z")

</div>

become\_user: root  
become: true  
become\_method: sudo
