# Need help to find how to run root command with non-root user and escalated privilages

**URL:** <https://forum.ansible.com/t/need-help-to-find-how-to-run-root-command-with-non-root-user-and-escalated-privilages/27562>\
**Category:** Ansible Project\
**Created:** [May 18, 2018, 7:26pm UTC](https://forum.ansible.com/t/need-help-to-find-how-to-run-root-command-with-non-root-user-and-escalated-privilages/27562 "2018-05-18T19:26:50Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kallu\_Srikanth](https://avatars.discourse-cdn.com/v4/letter/k/ee59a6/32.png) [@Kallu\_Srikanth](https://forum.ansible.com/u/Kallu_Srikanth)\
**Post date:** [May 18, 2018, 7:26pm UTC](https://forum.ansible.com/t/need-help-to-find-how-to-run-root-command-with-non-root-user-and-escalated-privilages/27562/1 "2018-05-18T19:26:50Z")

</div>

Hi,

I highly appreciate if anybody can help, please

############### playbook ##################

- hosts: dpie\_prod  
user: dpiesa  
tasks:
- name: install telnet  
yum: pkg=telnet state=installed update\_cache=true

# command: sudo yum install telnet -y

become: yes  
become\_user: root  
become\_method: sudo

The above does not work and throws this error

TASK [install telnet] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
[WARNING]: Module invocation had junk after the JSON data: usage: sudo -e [-S] [-p prompt] [-u username|#uid] file …

fatal: [[lind01.corp.acxiom.net](http://lind01.corp.acxiom.net)]: FAILED! =\> {“changed”: false, “module\_stderr”: “Shared connection to [lind01.corp.acxiom.net](http://lind01.corp.acxiom.net) closed.\r\n”, “module\_stdout”: “sudo: illegal option `-n’\r\nusage: sudo -h | -K | -k | -L | -l | -V | -v\r\nusage: sudo [-bEHPS] [-p prompt] [-u username|#uid] [VAR=value]\r\n {-i | -s | }\r\nusage: sudo -e [-S] [-p prompt] [-u username|#uid] file …\r\n”, “msg”: “MODULE FAILURE”, “rc”: 1}  
to retry, use: --limit @/home/dpiesa/playbooks/install\_telnet.retry

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [May 22, 2018, 3:34am UTC](https://forum.ansible.com/t/need-help-to-find-how-to-run-root-command-with-non-root-user-and-escalated-privilages/27562/2 "2018-05-22T03:34:57Z")

</div>

You seem to have a non standard/old sudo, change the default  
become\_flags as they seem to be causing the problem, specifically,  
remove -n (default: '-H -S -n'  
)

---

<div class="post-metadata">

**Author:** ![David\_Villasmil](https://avatars.discourse-cdn.com/v4/letter/d/a5b964/32.png) [@David\_Villasmil](https://forum.ansible.com/u/David_Villasmil)\
**Post date:** [May 22, 2018, 3:45am UTC](https://forum.ansible.com/t/need-help-to-find-how-to-run-root-command-with-non-root-user-and-escalated-privilages/27562/3 "2018-05-22T03:45:48Z")

</div>

I think if you set ‘become’ then you don’t need to use sudo.  
Also, why don’t you use the module to install packages instead of executing yum?  
[http://docs.ansible.com/ansible/latest/modules/yum\_module.html](http://docs.ansible.com/ansible/latest/modules/yum_module.html)

Example:

- name: install one specific version of Apache  
yum:  
name: httpd-2.2.29-1.4.amzn1  
state: present

---

<div class="post-metadata">

**Author:** ![abhay\_srivastava](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@abhay\_srivastava](https://forum.ansible.com/u/abhay_srivastava)\
**Post date:** [May 22, 2018, 3:59am UTC](https://forum.ansible.com/t/need-help-to-find-how-to-run-root-command-with-non-root-user-and-escalated-privilages/27562/4 "2018-05-22T03:59:20Z")

</div>

Try:

- hosts: dpie\_prod  
user: dpiesa  
become: True

tasks:

- name: install telnet  
yum: pkg=telnet state=installed update\_cache=true

# command: sudo yum install telnet -y

---

<div class="post-metadata">

**Author:** ![Kallu\_Srikanth](https://avatars.discourse-cdn.com/v4/letter/k/ee59a6/32.png) [@Kallu\_Srikanth](https://forum.ansible.com/u/Kallu_Srikanth)\
**Post date:** [May 22, 2018, 4:19pm UTC](https://forum.ansible.com/t/need-help-to-find-how-to-run-root-command-with-non-root-user-and-escalated-privilages/27562/5 "2018-05-22T16:19:39Z")

</div>

Not sure how can I specifically remove this -n

Below is my code/error/other info if you can help, please

Code : -

---

<div class="post-metadata">

**Author:** ![Kallu\_Srikanth](https://avatars.discourse-cdn.com/v4/letter/k/ee59a6/32.png) [@Kallu\_Srikanth](https://forum.ansible.com/u/Kallu_Srikanth)\
**Post date:** [May 22, 2018, 4:35pm UTC](https://forum.ansible.com/t/need-help-to-find-how-to-run-root-command-with-non-root-user-and-escalated-privilages/27562/6 "2018-05-22T16:35:25Z")

</div>

Hi Abhay i still have the error

Code : -

---

<div class="post-metadata">

**Author:** ![abhay\_srivastava](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@abhay\_srivastava](https://forum.ansible.com/u/abhay_srivastava)\
**Post date:** [May 22, 2018, 5:05pm UTC](https://forum.ansible.com/t/need-help-to-find-how-to-run-root-command-with-non-root-user-and-escalated-privilages/27562/7 "2018-05-22T17:05:20Z")

</div>

Are you able to do sudo without password

---

<div class="post-metadata">

**Author:** ![Kallu\_Srikanth](https://avatars.discourse-cdn.com/v4/letter/k/ee59a6/32.png) [@Kallu\_Srikanth](https://forum.ansible.com/u/Kallu_Srikanth)\
**Post date:** [May 22, 2018, 6:57pm UTC](https://forum.ansible.com/t/need-help-to-find-how-to-run-root-command-with-non-root-user-and-escalated-privilages/27562/8 "2018-05-22T18:57:15Z")

</div>

Brian, Actually it worked instead of removing -n i added “default: '-H -S” at the end of the file

Thank you very much, I really appreciate it
