Specify sudo password for Ansible

Question:

How do I specify a sudo password for Ansible in non-interactive way?

I’m running Ansible playbook like this:

But I want to run it like this:

Is there a way? I want to automate my project deployment as much as possible.

Answer:

You can pass variable on the command line via --extra-vars "name=value". Sudo password variable is ansible_sudo_pass. So your command would look like:

Update 2017: Ansible 2.2.1.0 now uses var ansible_become_pass. Either seems to work.

Update 2021: ansible_become_pass is still working, but for now, we should use -e instead of –extra-vars

Leave a Reply