# Setting the private SSH key from variables in a play?

**URL:** <https://forum.ansible.com/t/setting-the-private-ssh-key-from-variables-in-a-play/13211>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [July 29, 2013, 9:06am UTC](https://forum.ansible.com/t/setting-the-private-ssh-key-from-variables-in-a-play/13211 "2013-07-29T09:06:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark1](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@Mark1](https://forum.ansible.com/u/Mark1)\
**Post date:** [July 29, 2013, 9:06am UTC](https://forum.ansible.com/t/setting-the-private-ssh-key-from-variables-in-a-play/13211/1 "2013-07-29T09:06:55Z")

</div>

I want to be able to set the path to the private SSH key in a playbook so I don’t need to pass it on the command line all the time.

My use-case is having 10+ AWS accounts for dev/test/prod, etc. with separate keys for each. I’m not using EIPs so I can’t use host vars. Instead, in my plays I pass an ‘environment’ variable that specifies whether I’m in dev01, test02, etc., and variables for the relevant environment get loaded using vars\_files (I’m using ansible for provisioning new instances and snapshotting them as AMIs).

I know how to set the SSH user in playbooks, but how can I set the private SSH key path as well?

Mark

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [July 29, 2013, 1:49pm UTC](https://forum.ansible.com/t/setting-the-private-ssh-key-from-variables-in-a-play/13211/2 "2013-07-29T13:49:59Z")

</div>

Sure!

You can set ansible\_ssh\_private\_keyfile as an inventory variable with the path to your key.

see details here: [http://ansibleworks.com/docs/patterns.html#id3](http://ansibleworks.com/docs/patterns.html#id3)

---

<div class="post-metadata">

**Author:** ![Mark1](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@Mark1](https://forum.ansible.com/u/Mark1)\
**Post date:** [July 29, 2013, 2:52pm UTC](https://forum.ansible.com/t/setting-the-private-ssh-key-from-variables-in-a-play/13211/3 "2013-07-29T14:52:02Z")

</div>

Thanks, I’ll try it.
