# How to format the inventory file for amazon ec2 hosts?

**URL:** <https://forum.ansible.com/t/how-to-format-the-inventory-file-for-amazon-ec2-hosts/29878>\
**Category:** Ansible Project\
**Created:** [March 13, 2019, 9:45pm UTC](https://forum.ansible.com/t/how-to-format-the-inventory-file-for-amazon-ec2-hosts/29878 "2019-03-13T21:45:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gigit1000](https://avatars.discourse-cdn.com/v4/letter/g/a87d85/32.png) [@gigit1000](https://forum.ansible.com/u/gigit1000)\
**Post date:** [March 13, 2019, 9:45pm UTC](https://forum.ansible.com/t/how-to-format-the-inventory-file-for-amazon-ec2-hosts/29878/1 "2019-03-13T21:45:19Z")

</div>

Hello,

```auto
I am unable to run the example ad hoc command:

```

ansible -m ping hosts --private-key=~/home/ec2-user/ -u ec2-user

the error is: [WARNING]: Could not match supplied host pattern, ignoring: hosts

The hostname is: ip-10-200-2-21.us-west-2.compute.internal  
The host ip is: 10.200.2.21

I can ping the host from my ansible control node OS by this hostname.

I created the hosts file with the touch command and it looks like this:

ip-10-200-2-21.us-west-2.compute.internal

Do I need to include something more? Do I need to save it with a particular extension? Thank You much for any help.

---

<div class="post-metadata">

**Author:** ![gigit1000](https://avatars.discourse-cdn.com/v4/letter/g/a87d85/32.png) [@gigit1000](https://forum.ansible.com/u/gigit1000)\
**Post date:** [March 13, 2019, 11:07pm UTC](https://forum.ansible.com/t/how-to-format-the-inventory-file-for-amazon-ec2-hosts/29878/2 "2019-03-13T23:07:04Z")

</div>

the answer was to change hosts file to:

```auto
[ec2]
ip-10-200-2-21.us-west-2.compute.internal 

```

and change the command to:

```auto
ansible ec2 -m ping -i /etc/ansible/hosts

```
