two step process to become root

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. :slight_smile:

Regards,

Brad

https://docs.ansible.com/ansible/latest/user_guide/become.html

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

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

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'.

OK. Thanks for the feedback! :slight_smile: