Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible 2.1.2 playbook pass SSH password and sudo password as command line args

Tags:

ansible

I've looked around but couldn't find a proper solution, I want to run playbook for multiple users on multiple hosts and my roles use the user specific info such as name, email, id ... Now instead of running the playbook for each user I wrote a python script that invokes the ansible

ansible-playbook -i hosts --ask-become-pass --ask-pass ./playbooks/myplaybook.yml

But for the above command to work I want to pass SSH password and SUDO password as arguments to the command. I checked ansible-playbook documentation but was unable to find it. What would be the best way to achieve this?

like image 770
Chenna V Avatar asked Jan 20 '17 20:01

Chenna V


People also ask

How do you pass the sudo password in ansible playbook?

Providing the sudo Password If the remote user needs to provide a password in order to run sudo commands, you can include the option --ask-become-pass to your Ansible command. This will prompt you to provide the remote user sudo password: ansible all -m ping --ask-become-pass.

What is way to mention sudo privilege in ansible?

To specify a password for sudo, run ansible-playbook with --ask-become-pass ( -K for short). If you run a playbook utilizing become and the playbook seems to hang, most likely it is stuck at the privilege escalation prompt. Stop it with CTRL-c , then execute the playbook with -K and the appropriate password.


1 Answers

You can specify the following parameters from the command line:

… -e "ansible_user=username ansible_ssh_pass=xxx ansible_sudo_pass=xxx" …
like image 141
Thomas O'Brien Avatar answered Sep 18 '22 15:09

Thomas O'Brien