# Is it possible to pass SSH key contents as argument when running ansible-playbook

**URL:** <https://forum.ansible.com/t/is-it-possible-to-pass-ssh-key-contents-as-argument-when-running-ansible-playbook/28334>\
**Category:** Ansible Project\
**Created:** [August 15, 2018, 2:35pm UTC](https://forum.ansible.com/t/is-it-possible-to-pass-ssh-key-contents-as-argument-when-running-ansible-playbook/28334 "2018-08-15T14:35:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bruce\_Affonso](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@Bruce\_Affonso](https://forum.ansible.com/u/Bruce_Affonso)\
**Post date:** [August 15, 2018, 2:35pm UTC](https://forum.ansible.com/t/is-it-possible-to-pass-ssh-key-contents-as-argument-when-running-ansible-playbook/28334/1 "2018-08-15T14:35:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Tchia04](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@Tchia04](https://forum.ansible.com/u/Tchia04)\
**Post date:** [August 15, 2018, 2:54pm UTC](https://forum.ansible.com/t/is-it-possible-to-pass-ssh-key-contents-as-argument-when-running-ansible-playbook/28334/2 "2018-08-15T14:54:08Z")

</div>

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](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](https://docs.ansible.com/ansible/2.6/plugins/connection/paramiko_ssh.html)

Tony Chia
