Change user while executing ansible script.

19 views
Skip to first unread message

Nitin Mathur

unread,
Oct 28, 2016, 3:45:24 PM10/28/16
to Ansible Project
Hi,

I am trying to figure out, if the below scenario is possible and if so, how I can achieve it.

My target machine and ansible host is the same machine. There are 2 users, user-1(non-sudo privilege), user-2 (sudo privilege). Both user-1 and user-2 have passwords. I am logged in to my Ansible host as a user-1(non-sudo privilege) and execute an ansible script. I need to  execute this ansible script with sudo privileges meaning as user-2(with sudo privilege). Also the password entry should be non-interactive. Is there a way to do this using group_vars or any other way? 

Thanks in advance.

Alexander H. Laughlin

unread,
Oct 28, 2016, 4:16:19 PM10/28/16
to Ansible Project
If you store the password in a vaulted file I believe you can use su as the become method and accomplish this result.

Nitin Mathur

unread,
Oct 28, 2016, 4:34:54 PM10/28/16
to Ansible Project
Can you please provide an example or reference??

Alexander H. Laughlin

unread,
Oct 28, 2016, 9:29:18 PM10/28/16
to Ansible Project
Become documentation. 


It seems as though you need the root password and you should use a become method of 'su' to get done what you need done.

I'm not sure why you wouldn't just add user-1 to sudoers, though.
Reply all
Reply to author
Forward
0 new messages