How to Enter Private Key Password with Ansible

How to run an ansible-playbook with a passphrase-protected-ssh-private-key?

I solved it by running ssh-add once and use it like if it's not password protected.

How to enter private key password with ansible

Try using ssh as the transport. Generally, Ansible uses paramiko which is not as friendly for interactive sessions:

ansible all -c ssh -m ping

If that doesn't work, I didn't see anything on running Ansible with an ssh key pass phrase on the documentation or in the code, so you might have to remove it with something like this:

openssl rsa -in private_key_with_pass_phrase -out private_key_without_pass_phrase

Ansible Authenticate using Key with Passphrase

No, it defeats the purpose of using a password protected private key by bypassing the step of entering the password. If you are using some other method to authenticate the user that you are confident with then you could use a non-password protected private key but then you would need to have very good processes for managing your private key.

The point of ssh-agent is that you only need to enter the private key password once and not for each host you connect to or each time the session times out, it is not to bypass authenticating the owner of the private key.

Specify sudo password for Ansible

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:

ansible-playbook playbook.yml -i inventory.ini --user=username \
--extra-vars "ansible_sudo_pass=yourPassword"

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

How to pass a user / password in ansible command

The docs say you can specify the password via the command line:

-k, --ask-pass.

ask for connection password

Ansible can also store the password in the ansible_password variable on a per-host basis.



Related Topics



Leave a reply



Submit