# OpenStack Dynamic Inventory

**URL:** <https://forum.ansible.com/t/openstack-dynamic-inventory/14134>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [December 11, 2013, 10:29pm UTC](https://forum.ansible.com/t/openstack-dynamic-inventory/14134 "2013-12-11T22:29:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![AmiableAlbion](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@AmiableAlbion](https://forum.ansible.com/u/AmiableAlbion)\
**Post date:** [December 11, 2013, 10:29pm UTC](https://forum.ansible.com/t/openstack-dynamic-inventory/14134/1 "2013-12-11T22:29:33Z")

</div>

Hi All,  
I am trying to use the nova.py script provided as a jumping off point for using OpenStack as a dynamic inventory repository.I am experiencing a problem where the script does not work if I use the hostname (claims there is no host by that name). It works fine if I use the IP address. In fact, if I modify the nova.py script to return the JSON associated with a particular hostname, Ansible still claims that “No hosts matched”.

I guess I don’t understand what Ansible is using in the JSON to key on for the hostname. I am using version 1.3.3.

At least looking at the EC2 example, I see a hostname specified:

**ansible -i ec2.py -u ubuntu us-east-1d -m ping**

This looks like its logging in as the user ubuntu to the host us-east-1d. I am looking for the same behavior in an OpenStack environment.

Albion

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [December 11, 2013, 10:59pm UTC](https://forum.ansible.com/t/openstack-dynamic-inventory/14134/2 "2013-12-11T22:59:22Z")

</div>

So what you select for the host pattern will need to match what comes back from the inventory script

do ./ec2.py --list to see what names come back

you can also just reference host by groups

---

<div class="post-metadata">

**Author:** ![AmiableAlbion](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@AmiableAlbion](https://forum.ansible.com/u/AmiableAlbion)\
**Post date:** [December 11, 2013, 11:26pm UTC](https://forum.ansible.com/t/openstack-dynamic-inventory/14134/3 "2013-12-11T23:26:57Z")

</div>

Hi Michael,  
Thanks, this sheds some light on it (and works as you indicated).

So what is going on under the hood? Is Ansible just calling the nova.py script with **–list** to get the groups and hostname(s)? Is the **–host** just for the user or is that called for other functions?

Thanks, this is very helpful.  
Albion

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [December 11, 2013, 11:37pm UTC](https://forum.ansible.com/t/openstack-dynamic-inventory/14134/4 "2013-12-11T23:37:02Z")

</div>

–host is called to get variables for the host if and only if the inventory script is not optimized to return things all in one call.

More details that should be helpful are listed here:

[http://ansibleworks.com/docs/intro\_dynamic\_inventory.html](http://ansibleworks.com/docs/intro_dynamic_inventory.html)

and regarding that specifically:

[http://ansibleworks.com/docs/developing\_inventory.html](http://ansibleworks.com/docs/developing_inventory.html)

---

<div class="post-metadata">

**Author:** ![AmiableAlbion](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@AmiableAlbion](https://forum.ansible.com/u/AmiableAlbion)\
**Post date:** [December 11, 2013, 11:44pm UTC](https://forum.ansible.com/t/openstack-dynamic-inventory/14134/5 "2013-12-11T23:44:37Z")

</div>

Hi Michael.

I modified the nova.py script since it turns out it was setup to key on the host IP address (public or private). My version resolves by hostname using the instance “name” attribute.

Thanks again.  
Albion
