# ec2 Dynamic inventory and hostname

**URL:** <https://forum.ansible.com/t/ec2-dynamic-inventory-and-hostname/15526>\
**Category:** Ansible Project\
**Created:** [June 23, 2014, 4:25pm UTC](https://forum.ansible.com/t/ec2-dynamic-inventory-and-hostname/15526 "2014-06-23T16:25:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hernandes\_Sousa](https://avatars.discourse-cdn.com/v4/letter/h/eb8c5e/32.png) [@Hernandes\_Sousa](https://forum.ansible.com/u/Hernandes_Sousa)\
**Post date:** [June 23, 2014, 4:25pm UTC](https://forum.ansible.com/t/ec2-dynamic-inventory-and-hostname/15526/1 "2014-06-23T16:25:46Z")

</div>

Hi,

I wanted to use the machine hostnames with ec2.py, which I was able to by customizing the script to return the Name tag for the hostname instead of the public or private dns name, however, that requires an extra step which is maintaining a ~/.ssh/config with corresponding proper dns since I’m not currently using fqdns as the hostnames (will do in the near future so this will not actually be necessary). But in the meanwhile I’d like to be able to do as in the static inventory:

```auto
foo ansible_ssh_host=192.168.1.50

```

Is it possible to do this with the dynamic inventory (have an alias for a machine which is the name tag i already set but connect using public dns)?

---

<div class="post-metadata">

**Author:** ![senorsmile](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/senorsmile/32/9024_2.png) [@senorsmile](https://forum.ansible.com/u/senorsmile)\
**Post date:** [June 24, 2015, 3:45pm UTC](https://forum.ansible.com/t/ec2-dynamic-inventory-and-hostname/15526/2 "2015-06-24T15:45:13Z")

</div>

+1 this would be awesome.

---

<div class="post-metadata">

**Author:** ![Hagai\_Kariti](https://avatars.discourse-cdn.com/v4/letter/h/4491bb/32.png) [@Hagai\_Kariti](https://forum.ansible.com/u/Hagai_Kariti)\
**Post date:** [June 28, 2015, 7:58am UTC](https://forum.ansible.com/t/ec2-dynamic-inventory-and-hostname/15526/3 "2015-06-28T07:58:26Z")

</div>

There’s a pull request for this. It allows you to specify a hostname\_variable in ec2.ini to a host attr or tag, so that inventory\_hostname will be set to this value while still keeping ansible\_ssh\_host intact (i.e. still using the destination\_variable setting).

[https://github.com/ansible/ansible/pull/7395](https://github.com/ansible/ansible/pull/7395)
