# Running a script as root user.

**URL:** <https://forum.ansible.com/t/running-a-script-as-root-user/31541>\
**Category:** Ansible Project\
**Created:** [October 24, 2019, 9:15pm UTC](https://forum.ansible.com/t/running-a-script-as-root-user/31541 "2019-10-24T21:15:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dave\_McPherson](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dave_mcpherson/32/6973_2.png) [@Dave\_McPherson](https://forum.ansible.com/u/Dave_McPherson)\
**Post date:** [October 24, 2019, 9:15pm UTC](https://forum.ansible.com/t/running-a-script-as-root-user/31541/1 "2019-10-24T21:15:23Z")

</div>

Hi All,

I have a script that I need to run on oracle linux when I try the standard “become:” it fails with the error “run with sudo -s”

I have tried many variations but what I have now is below.

- name: Run gold\_changes  
shell: /home/em7admin/gold\_changes\_8x.sh -y  
become\_user: root  
become\_method: su  
become: true  
register: script

Any help would be appreciated.

Dave

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [October 24, 2019, 11:05pm UTC](https://forum.ansible.com/t/running-a-script-as-root-user/31541/2 "2019-10-24T23:05:18Z")

</div>

Try \*sudo\* plugin  
[https://docs.ansible.com/ansible/latest/plugins/become/sudo.html](https://docs.ansible.com/ansible/latest/plugins/become/sudo.html)

&nbsp;&nbsp;&nbsp;&nbsp;become\_method: sudo

Try \*command\* module  
[https://docs.ansible.com/ansible/latest/modules/command\_module.html#command-module](https://docs.ansible.com/ansible/latest/modules/command_module.html#command-module)

&nbsp;&nbsp;&nbsp;&nbsp;command: /home/em7admin/gold\_changes\_8x.sh -y

Quoting from \*shell\* module: "If you want to execute a command securely and  
predictably, it may be better to use the command module instead..."  
[https://docs.ansible.com/ansible/latest/modules/shell\_module.html](https://docs.ansible.com/ansible/latest/modules/shell_module.html)

Cheers,

&nbsp;&nbsp;-vlado
