# Run one simple coomand with sudo priviliges.

**URL:** <https://forum.ansible.com/t/run-one-simple-coomand-with-sudo-priviliges/27593>\
**Category:** Ansible Project\
**Created:** [May 22, 2018, 12:40pm UTC](https://forum.ansible.com/t/run-one-simple-coomand-with-sudo-priviliges/27593 "2018-05-22T12:40:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dawid\_D](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@Dawid\_D](https://forum.ansible.com/u/Dawid_D)\
**Post date:** [May 22, 2018, 12:40pm UTC](https://forum.ansible.com/t/run-one-simple-coomand-with-sudo-priviliges/27593/1 "2018-05-22T12:40:20Z")

</div>

Hello All,  
I would like ask about privileges escalation by sudo.

I need run command on **RemoteMachine**. **User: someone** and **Command: /usr/local/blah.sh** for example

suoders file:

`someone RemoteMachine =(root) **/usr/local/blah.sh** `

Unfortunately I can’t give permission to switch root, and **I can’t give** NOPASSWD phrase in sudoers.

I tried by:

`

shell: /usr/local/blah.sh  
**become: yes**  
**become\_method: sudo**

`

But it is failed because ansible trying switch to user before run command.

I tried also:

`shell: " **sudo** /usr/local/blah.sh"`

But this one hanging ansible, because he is waiting for sudo password.

Is there any possibility to just run command with sudo and provide password automatically ?

I will be very happy for help.

Than you Ansible community,  
Regards Dawid D.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [May 22, 2018, 6:08pm UTC](https://forum.ansible.com/t/run-one-simple-coomand-with-sudo-priviliges/27593/2 "2018-05-22T18:08:38Z")

</div>

> Hello All,  
> &nbsp;&nbsp;&nbsp;&nbsp;I would like ask about privileges escalation by sudo.
> 
> &nbsp;&nbsp;&nbsp;&nbsp;I need run command on \*RemoteMachine\*. \*User: someone\* and \*Command:  
> /usr/local/blah.sh \*for example
> 
> &nbsp;&nbsp;&nbsp;&nbsp;suoders file:  
> someone RemoteMachine =(root)\*/usr/local/blah.sh\*
> 
> &nbsp;&nbsp;&nbsp;&nbsp;Unfortunately I can't give permission to switch root, and \*I can't give\*  
> NOPASSWD phrase in sudoers.
> 
> &nbsp;&nbsp;&nbsp;&nbsp;I tried by:  
> shell: /usr/local/blah.sh  
> \*become: yes\*  
> \*become\_method: sudo\*
> 
> &nbsp;&nbsp;&nbsp;&nbsp;But it is failed because ansible trying switch to user before run  
> command.

This, the shell module, actually run "sudo /some/python/script" and that script run plain "/usr/local/blah.sh"

> &nbsp;&nbsp;&nbsp;&nbsp;I tried also:  
> shell: "\*sudo\* /usr/local/blah.sh"
> 
> &nbsp;&nbsp;&nbsp;&nbsp;But this one hanging ansible, because he is waiting for sudo password.
> 
> &nbsp;&nbsp;&nbsp;&nbsp;Is there any possibility to just run command with sudo and provide  
> password automatically ?

sudo do support -S for reading the password from stdin.
