# become root user using custom command in ansible

**URL:** <https://forum.ansible.com/t/become-root-user-using-custom-command-in-ansible/36026>\
**Category:** Ansible Project\
**Created:** [November 23, 2021, 1:06pm UTC](https://forum.ansible.com/t/become-root-user-using-custom-command-in-ansible/36026 "2021-11-23T13:06:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hanumantha\_Reddy\_Bas](https://avatars.discourse-cdn.com/v4/letter/h/c67d28/32.png) [@Hanumantha\_Reddy\_Bas](https://forum.ansible.com/u/Hanumantha_Reddy_Bas)\
**Post date:** [November 23, 2021, 1:06pm UTC](https://forum.ansible.com/t/become-root-user-using-custom-command-in-ansible/36026/1 "2021-11-23T13:06:58Z")

</div>

Hello All,

In target server need to run a command like “mcs cmh” which prompts for password to become root user… how can I achieve the same in become method?

Thanks,

BHR.

---

<div class="post-metadata">

**Author:** ![steve\_missoh](https://avatars.discourse-cdn.com/v4/letter/s/3da27b/32.png) [@steve\_missoh](https://forum.ansible.com/u/steve_missoh)\
**Post date:** [November 23, 2021, 1:32pm UTC](https://forum.ansible.com/t/become-root-user-using-custom-command-in-ansible/36026/2 "2021-11-23T13:32:21Z")

</div>

You need to configure sudo on the target server.  
and then use

become\_method = sudo  
become = yes

in your ansible.cfg

---

<div class="post-metadata">

**Author:** ![Hanumantha\_Reddy\_Bas](https://avatars.discourse-cdn.com/v4/letter/h/c67d28/32.png) [@Hanumantha\_Reddy\_Bas](https://forum.ansible.com/u/Hanumantha_Reddy_Bas)\
**Post date:** [November 23, 2021, 2:12pm UTC](https://forum.ansible.com/t/become-root-user-using-custom-command-in-ansible/36026/3 "2021-11-23T14:12:54Z")

</div>

As per my understanding if we are able to run command sudo su - root in target server then can use become\_method as sudo… but need to run custom command mcs cmh to login as root user in target server. I don’t think so we can use become\_metod = sudo in this scenario.

---

<div class="post-metadata">

**Author:** ![steve\_missoh](https://avatars.discourse-cdn.com/v4/letter/s/3da27b/32.png) [@steve\_missoh](https://forum.ansible.com/u/steve_missoh)\
**Post date:** [November 23, 2021, 2:28pm UTC](https://forum.ansible.com/t/become-root-user-using-custom-command-in-ansible/36026/4 "2021-11-23T14:28:20Z")

</div>

Not use I get all your explanations, but maybe u can also look at:  
ansible\_become\_user=root and ansible\_become\_pass=XXXX to set in your inventory file ?
