# two step process to become root

**URL:** <https://forum.ansible.com/t/two-step-process-to-become-root/28693>\
**Category:** Ansible Project\
**Created:** [October 1, 2018, 12:51pm UTC](https://forum.ansible.com/t/two-step-process-to-become-root/28693 "2018-10-01T12:51:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brad2](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Brad2](https://forum.ansible.com/u/Brad2)\
**Post date:** [October 1, 2018, 12:51pm UTC](https://forum.ansible.com/t/two-step-process-to-become-root/28693/1 "2018-10-01T12:51:46Z")

</div>

I’m looking for suggestions on how to add a two step login/switch to root to work within ansible. I’m restricted to logining in to a server with my normal sid. After that is accomplished, I then use su to switch to another account (giving a password when prompted). From there, I can use sudo to switch to root. Trying to wrap my head around putting that into practice within ansible. Suggestions would be greatly appreciated. 🙂

Regards,

Brad

---

<div class="post-metadata">

**Author:** ![Jonathan\_Lozada\_De\_L](https://avatars.discourse-cdn.com/v4/letter/j/eb8c5e/32.png) [@Jonathan\_Lozada\_De\_L](https://forum.ansible.com/u/Jonathan_Lozada_De_L)\
**Post date:** [October 1, 2018, 12:56pm UTC](https://forum.ansible.com/t/two-step-process-to-become-root/28693/2 "2018-10-01T12:56:54Z")

</div>

[https://docs.ansible.com/ansible/latest/user\_guide/become.html](https://docs.ansible.com/ansible/latest/user_guide/become.html)

---

<div class="post-metadata">

**Author:** ![Dilson\_Tome](https://avatars.discourse-cdn.com/v4/letter/d/839c29/32.png) [@Dilson\_Tome](https://forum.ansible.com/u/Dilson_Tome)\
**Post date:** [October 1, 2018, 1:12pm UTC](https://forum.ansible.com/t/two-step-process-to-become-root/28693/3 "2018-10-01T13:12:00Z")

</div>

You can use become to change to this generic user and set sudo in your commands.

---

<div class="post-metadata">

**Author:** ![Brad2](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Brad2](https://forum.ansible.com/u/Brad2)\
**Post date:** [October 1, 2018, 1:31pm UTC](https://forum.ansible.com/t/two-step-process-to-become-root/28693/4 "2018-10-01T13:31:21Z")

</div>

Yes, I’ve been reading that. Not really clear. Maybe (setting ansible\_become\_pass in the inventory file):

`

- name: switch to intermediate user  
command: cat /dev/null  
become: yes  
become\_method: su  
become\_user: sid-other
- name: switch to root  
command: cat /dev/null  
become: yes  
become\_method: sudo  
become\_user: root

`

Would that achieve what I am looking for and then run every subsequent command as root?

Regards,

Brad

---

<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:** [October 1, 2018, 1:40pm UTC](https://forum.ansible.com/t/two-step-process-to-become-root/28693/5 "2018-10-01T13:40:17Z")

</div>

No, each task happens in it's own session, setting the environment in  
task1 does not affect task2.

Ansible does not support the scheme you have as it requires 2  
privilege escalation systems into every execution, they are not  
currently 'stackable'.

---

<div class="post-metadata">

**Author:** ![Brad2](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Brad2](https://forum.ansible.com/u/Brad2)\
**Post date:** [October 1, 2018, 1:49pm UTC](https://forum.ansible.com/t/two-step-process-to-become-root/28693/6 "2018-10-01T13:49:32Z")

</div>

OK. Thanks for the feedback! 🙂
