Specify sudo password for Ansible


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.


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 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