# Noob Issue with using AWS hostnames in inventory

**URL:** <https://forum.ansible.com/t/noob-issue-with-using-aws-hostnames-in-inventory/22836>\
**Category:** Ansible Developer\
**Tags:** aws\
**Created:** [October 20, 2016, 2:27am UTC](https://forum.ansible.com/t/noob-issue-with-using-aws-hostnames-in-inventory/22836 "2016-10-20T02:27:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sonny\_Chee](https://avatars.discourse-cdn.com/v4/letter/s/edb3f5/32.png) [@Sonny\_Chee](https://forum.ansible.com/u/Sonny_Chee)\
**Post date:** [October 20, 2016, 2:27am UTC](https://forum.ansible.com/t/noob-issue-with-using-aws-hostnames-in-inventory/22836/1 "2016-10-20T02:27:30Z")

</div>

Hey Guys,

I am successful executing ansible against an AWS ec2 when I put the public IP in the /etc/ansible/hosts file. However, when I replace that with the ec2 hostname, ansible complains with:

[ec2-xx-xxx-xxx-xx.compute-1.amazonaws.com](http://ec2-xx-xxx-xxx-xx.compute-1.amazonaws.com) | UNREACHABLE! =\> {  
“changed”: false,  
“msg”: “Failed to connect to the host via ssh.”,  
“unreachable”: true  
}

Any help would be appreciated…

---

<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:** [October 20, 2016, 4:50am UTC](https://forum.ansible.com/t/noob-issue-with-using-aws-hostnames-in-inventory/22836/2 "2016-10-20T04:50:20Z")

</div>

To debug, run with -vvv and you’ll see the full ssh command, see if you can run that manually.

---

<div class="post-metadata">

**Author:** ![Josh\_Smift1](https://avatars.discourse-cdn.com/v4/letter/j/bcef8e/32.png) [@Josh\_Smift1](https://forum.ansible.com/u/Josh_Smift1)\
**Post date:** [October 20, 2016, 11:13am UTC](https://forum.ansible.com/t/noob-issue-with-using-aws-hostnames-in-inventory/22836/3 "2016-10-20T11:13:31Z")

</div>

There's also some ec2.ini configuration that controls whether Ansible uses  
private or public addresses or names to refer to your instances, and the  
ability to have Ansible use one thing for inventory\_hostname and another  
for the actual SSH connection. Which combination of things you want  
depends on what you're doing, e.g. Ansible running on the same private  
network as your instances or not, etc.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-Josh (jbs@care.com)

(apologies for the automatic corporate disclaimer that follows)

This email is intended for the person(s) to whom it is addressed and may contain information that is PRIVILEGED or CONFIDENTIAL. Any unauthorized use, distribution, copying, or disclosure by any person other than the addressee(s) is strictly prohibited. If you have received this email in error, please notify the sender immediately by return email and delete the message and any attachments from your system.

---

<div class="post-metadata">

**Author:** ![Sonny\_Chee](https://avatars.discourse-cdn.com/v4/letter/s/edb3f5/32.png) [@Sonny\_Chee](https://forum.ansible.com/u/Sonny_Chee)\
**Post date:** [October 20, 2016, 5:47pm UTC](https://forum.ansible.com/t/noob-issue-with-using-aws-hostnames-in-inventory/22836/4 "2016-10-20T17:47:39Z")

</div>

Thanks for the pointer, Josh.

However, I don’t think that is the issue, within the ini file I do have:

destination\_variable = public\_dns\_name

---

<div class="post-metadata">

**Author:** ![Josh\_Smift1](https://avatars.discourse-cdn.com/v4/letter/j/bcef8e/32.png) [@Josh\_Smift1](https://forum.ansible.com/u/Josh_Smift1)\
**Post date:** [October 20, 2016, 6:16pm UTC](https://forum.ansible.com/t/noob-issue-with-using-aws-hostnames-in-inventory/22836/5 "2016-10-20T18:16:03Z")

</div>

> Thanks for the pointer, Josh.
> 
> However, I don't think that is the issue, within the ini file I do have:
> 
> destination\_variable = public\_dns\_name

Mm. And can you in fact SSH to your instances from your Ansible control  
host by their public DNS names?

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-Josh (jbs@care.com)  
This email is intended for the person(s) to whom it is addressed and may contain information that is PRIVILEGED or CONFIDENTIAL. Any unauthorized use, distribution, copying, or disclosure by any person other than the addressee(s) is strictly prohibited. If you have received this email in error, please notify the sender immediately by return email and delete the message and any attachments from your system.
