Reputation: 259
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
Reputation: 379
this is what working for me ...
become: yes
become_method: sudo
become_user: myuser
become_flags: 'su -c'
Upvotes: 5
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