# Hostnames with EC2 inventory plugin

**URL:** <https://forum.ansible.com/t/hostnames-with-ec2-inventory-plugin/27237>\
**Category:** Ansible Project\
**Created:** [April 11, 2018, 7:19am UTC](https://forum.ansible.com/t/hostnames-with-ec2-inventory-plugin/27237 "2018-04-11T07:19:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![oscar](https://avatars.discourse-cdn.com/v4/letter/o/22d042/32.png) [@oscar](https://forum.ansible.com/u/oscar)\
**Post date:** [April 11, 2018, 7:19am UTC](https://forum.ansible.com/t/hostnames-with-ec2-inventory-plugin/27237/1 "2018-04-11T07:19:51Z")

</div>

Hi,

I’m testing the new Amazon EC2 dynamic inventory plugin. I need to set the host names to the “Name” tag, but I don’t understand the documentation. Reading this: [http://docs.ansible.com/ansible/latest/plugins/inventory/aws\_ec2.html](http://docs.ansible.com/ansible/latest/plugins/inventory/aws_ec2.html) I understand I should write something like this:

`

```auto
    hostnames:
      - tag:Name=Name

```

`

But it doesn’t work. Also tried:

`

```auto
    hostnames:
      - tag-Key:Name

```

`

With no result. Also checked [https://www.ansible.com/blog/dynamic-inventory-past-present-future](https://www.ansible.com/blog/dynamic-inventory-past-present-future), but gives no additional information about how to do it. Do you know the way to set inventory hostname to the Name tag? It’s the configuration I’m using to test:

`  
plugin: aws\_ec2  
boto\_profile: default  
regions:

# Regions to include in the inventory

- us-east-1  
filters:

# Criteria to include hosts in the inventory

tag:Environment: staging  
instance-state-name: running  
hostnames:

- tag:Name  
#- private-dns-name  
strict\_permissions: False

`

Regards,  
Oscar

---

<div class="post-metadata">

**Author:** ![flowerysong1](https://avatars.discourse-cdn.com/v4/letter/f/ecae2f/32.png) [@flowerysong1](https://forum.ansible.com/u/flowerysong1)\
**Post date:** [April 11, 2018, 9:36am UTC](https://forum.ansible.com/t/hostnames-with-ec2-inventory-plugin/27237/2 "2018-04-11T09:36:45Z")

</div>

The inventory plugin does not currently have useful support for setting hostnames from tags. I submitted a pull request ([https://github.com/ansible/ansible/pull/35880](https://github.com/ansible/ansible/pull/35880)) to add this functionality, but it hasn’t been merged yet.

---

<div class="post-metadata">

**Author:** ![oscar](https://avatars.discourse-cdn.com/v4/letter/o/22d042/32.png) [@oscar](https://forum.ansible.com/u/oscar)\
**Post date:** [April 12, 2018, 7:45am UTC](https://forum.ansible.com/t/hostnames-with-ec2-inventory-plugin/27237/3 "2018-04-12T07:45:41Z")

</div>

Thank you very much for the information, and for the work! seems like ansible developers accepeted it, wich are great news.

Regards,  
Oscar
