Hi,
We are storing private keys in a DB and when we need to run a playbook would like to pass these SSH keys as an argument instead of storing as a file locally.
I tried something like this:
ansible-playbook -i “1.2.3.4,” --extra-vars=“ansible_user=username ansible_ssh_private_key_file=$KEY” playbooks/playbook.yml
but get message ‘No such file or directory’
It works if I specify a key file (and location). $KEY in an environment variable with private key contents.
So, is there a way to pass $KEY without having to create a file?
Thank you
Tchia04
(Tchia04)
August 15, 2018, 2:54pm
2
According to this page it doesn’t seem you have to store the key locally and replace it using an environment variable or an ansible variable
https://docs.ansible.com/ansible/2.6/plugins/connection/ssh.html
You can remove the key file after the playbook is finished
There is another option where you don’t have to temporarily store the credential on disk which is using the paramikio_ssh connection. The documentation is located at
https://docs.ansible.com/ansible/2.6/plugins/connection/paramiko_ssh.html
Tony Chia