# Search on AWS inventory and add to hosts

**URL:** <https://forum.ansible.com/t/search-on-aws-inventory-and-add-to-hosts/17045>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [December 13, 2014, 9:39am UTC](https://forum.ansible.com/t/search-on-aws-inventory-and-add-to-hosts/17045 "2014-12-13T09:39:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Navid\_Paya](https://avatars.discourse-cdn.com/v4/letter/n/9fc29f/32.png) [@Navid\_Paya](https://forum.ansible.com/u/Navid_Paya)\
**Post date:** [December 13, 2014, 9:39am UTC](https://forum.ansible.com/t/search-on-aws-inventory-and-add-to-hosts/17045/1 "2014-12-13T09:39:35Z")

</div>

Hi all  
I have come up with a search on AWS inventory. What I want to do is add the resulted instances to using add\_host. This is how use ec2.py to find the instances:

ec2.py ‘tag\_Name\_basebox\_myteksi\_net:&tag\_Provisioned\_False’

What would the task for this look like?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [December 15, 2014, 11:52am UTC](https://forum.ansible.com/t/search-on-aws-inventory-and-add-to-hosts/17045/2 "2014-12-15T11:52:52Z")

</div>

It would look like this, simply using the add host module to create a new group based on that pattern.

- hosts: tag\_Name\_basebox\_myteksi\_net:&tag\_Provisioned\_False  
tasks:
- add\_host: key=my\_new\_dynamic\_group\_alias

Note that this would only happen in memory, to do other things, you might wish to use the ec2\_tag module to assign new tags as well.

Hope this helps and let me know if there are any questions!
