mohan
mohan

Reputation: 259

How to achieve sudo su - <user> and run all command in ansible

I have an ssh access to the box but to run certain commands I need to do sudo su - and enter the password. Then I can run all the commands under that user.

How can i achieve this ansible. I tried become and sudo nothing worked for me.

Can someone provide me a working example?

Upvotes: 4

Views: 12785

Answers (2)

Shirish Shukla
Shirish Shukla

Reputation: 379

this is what working for me ...

become: yes
become_method: sudo
become_user: myuser
become_flags: 'su -c'

Upvotes: 5

Xiong Chiamiov
Xiong Chiamiov

Reputation: 13704

Ansible uses the become directive to control privilege escalation.

If you're using sudo su -, you're using sudo to raise your privileges (and su - merely launches an interactive shell). become_method should be set to "sudo".

Since you aren't using password-less sudo, you need to tell Ansible that you will be supplying a password. You can do this in a config file with ansible_become_pass, but a much more secure method is to invoke ansible with --ask-become-pass.

Upvotes: 1

Related Questions