# Any way to specify SSH key file for EC2 host using EC2 inventory

**URL:** <https://forum.ansible.com/t/any-way-to-specify-ssh-key-file-for-ec2-host-using-ec2-inventory/18353>\
**Category:** Ansible Project\
**Created:** [May 30, 2015, 6:06pm UTC](https://forum.ansible.com/t/any-way-to-specify-ssh-key-file-for-ec2-host-using-ec2-inventory/18353 "2015-05-30T18:06:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Do\_Hoang\_Khiem](https://avatars.discourse-cdn.com/v4/letter/d/3d9bf3/32.png) [@Do\_Hoang\_Khiem](https://forum.ansible.com/u/Do_Hoang_Khiem)\
**Post date:** [May 30, 2015, 6:06pm UTC](https://forum.ansible.com/t/any-way-to-specify-ssh-key-file-for-ec2-host-using-ec2-inventory/18353/1 "2015-05-30T18:06:09Z")

</div>

I’m using Ansible to manage multiple EC2 instance that could be launched dynamically, keypair is generated for each instance then store in local machine.

Previously I use default inventory file and in Ansible I can use lineinfile module to add new EC2 host to hosts file with additional vars like ansible\_ssh\_user, ansible\_ssh\_private\_key\_file, that’s very convenient as each time I run Ansible playbook I dont have to explicitly specify SSH key.

But now with change to use EC2 inventory, I can’t find a way to add such kind of vars to EC2 host, I know using ssh-agent is a solution, but I would look for a more explicit method that I can manage keys better than just add every generated key to ssh-agent.

Any suggestions?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 1, 2015, 2:09pm UTC](https://forum.ansible.com/t/any-way-to-specify-ssh-key-file-for-ec2-host-using-ec2-inventory/18353/2 "2015-06-01T14:09:20Z")

</div>

create host\_vars/\<hostname\> yaml files with the same info, in a  
directory adjacent to the dynamic inventory.
