Specify sudo password for Ansible

Slava Fomin II picture Slava Fomin II · Feb 19, 2014 · Viewed 290.8k times · Source

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

I'm running Ansible playbook like this:

$ ansible-playbook playbook.yml -i inventory.ini \
    --user=username --ask-sudo-pass

But I want to run it like this:

$ ansible-playbook playbook.yml -i inventory.ini \
    --user=username` **--sudo-pass=12345**

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

Answer

deefour picture deefour · Nov 26, 2014

The docs strongly recommend against setting the sudo password in plaintext, and instead using --ask-sudo-pass on the command line when running ansible-playbook


2016 Update:

Ansible 2.0 (not 100% when) marked --ask-sudo-pass as deprecated. The docs now recommend using --ask-become-pass instead, while also swapping out the use of sudo throughout your playbooks with become.