# Dynamic Inventory

**URL:** <https://forum.ansible.com/t/dynamic-inventory/20596>\
**Category:** Ansible Project\
**Created:** [February 16, 2016, 10:05pm UTC](https://forum.ansible.com/t/dynamic-inventory/20596 "2016-02-16T22:05:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Govindaraj\_Venkatesa](https://avatars.discourse-cdn.com/v4/letter/g/a698b9/32.png) [@Govindaraj\_Venkatesa](https://forum.ansible.com/u/Govindaraj_Venkatesa)\
**Post date:** [February 16, 2016, 10:05pm UTC](https://forum.ansible.com/t/dynamic-inventory/20596/1 "2016-02-16T22:05:30Z")

</div>

Hi,

Is there any script that we can use to construct dynamic inventory file for Openstack?

I downloaded the script but it gives a JSON output. Does anyone have a script to convert JSON to update a inventory file with list of IP address?  
You can download the latest version of the OpenStack inventory script at: [https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/openstack.py](https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/openstack.py)

Thanks,  
Govind

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [February 16, 2016, 10:07pm UTC](https://forum.ansible.com/t/dynamic-inventory/20596/2 "2016-02-16T22:07:16Z")

</div>

The dynamic inventory scripts are supposed to be used in place of a ini formatted inventory.

Instead of using `-i /path/to/ini/inventory` you would use `-i /path/to/openstack.py`

To make that possible, the `openstack.py` file needs to be marked as executable.

---

<div class="post-metadata">

**Author:** ![Govindaraj\_Venkatesa](https://avatars.discourse-cdn.com/v4/letter/g/a698b9/32.png) [@Govindaraj\_Venkatesa](https://forum.ansible.com/u/Govindaraj_Venkatesa)\
**Post date:** [February 16, 2016, 10:12pm UTC](https://forum.ansible.com/t/dynamic-inventory/20596/3 "2016-02-16T22:12:22Z")

</div>

Thanks Matt.

How do i execute this dynamic inventory against my playbook? When i tried the below it says no hosts matches.

#ansible-playbook jenkins\_mesos\_slave.yml -i openstack.py --limit [jmesosslv-cmce-02p.sys.comcast.net](http://jmesosslv-cmce-02p.sys.comcast.net)

Here is my playbook. How can i ensure my playbook can run against this dynamic inventory file?

#vi jenkins\_mesos\_slave.yml

- hosts: jenkins\_mesos\_slave\_prod  
become: yes  
become\_method: sudo  
roles:
- vmsetup
- mesos\_slave

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [February 16, 2016, 10:18pm UTC](https://forum.ansible.com/t/dynamic-inventory/20596/4 "2016-02-16T22:18:10Z")

</div>

Effectively ansible is calling that inventory like `./openstack.py --list`

You would need to inspect the output to see what is available.

You are specifying a hosts entry of `jenkins_mesos_slave_prod`, so the dynamic inventory would need to return that group for it to be used.

---

<div class="post-metadata">

**Author:** ![Govindaraj\_Venkatesa](https://avatars.discourse-cdn.com/v4/letter/g/a698b9/32.png) [@Govindaraj\_Venkatesa](https://forum.ansible.com/u/Govindaraj_Venkatesa)\
**Post date:** [February 17, 2016, 12:25am UTC](https://forum.ansible.com/t/dynamic-inventory/20596/5 "2016-02-17T00:25:16Z")

</div>

Hi Matt,

Here is the output from running openstack.py --list. Took a snippet of it.

“interface\_ip”: “96.119.246.10”,  
“key\_name”: “ssd-xplat”,  
“metadata”: {  
“cluster\_name”: “jenkins\_mesos\_master”,  
“group”: “mesos\_masters”,  
“master\_count”: “3”,  
“myid”: “3”  
},

$ ansible-playbook jenkins\_mesos\_master.yml -i openstack.py --limit 96.119.246.10 --check  
ERROR! Specified --limit does not match any hosts

Here is my jenkins\_mesos\_master.yml playbook

- hosts: **mesos\_masters** (should this be the group name that i need to use? )  
serial: “50%”  
become: yes  
become\_method: sudo  
roles:
- vmsetup
- mesos\_master

---

<div class="post-metadata">

**Author:** ![Govindaraj\_Venkatesa](https://avatars.discourse-cdn.com/v4/letter/g/a698b9/32.png) [@Govindaraj\_Venkatesa](https://forum.ansible.com/u/Govindaraj_Venkatesa)\
**Post date:** [February 17, 2016, 12:35am UTC](https://forum.ansible.com/t/dynamic-inventory/20596/6 "2016-02-17T00:35:50Z")

</div>

Hi Matt,

How can i force openstack.py script to write IPv4 address? For some reason the JSON file has IPv6 address.

“mesos\_masters”: [  
“b9d2e61e-0653-4a1f-a472-c5f15a017eae”,  
“ca8c9fc7-337f-4f92-baac-7fe41f6475ce”,  
“a904e509-b4b1-479e-8137-17bb30b400c9”  
],

I tried the below and it worked

ansible-playbook jenkins\_mesos\_master.yml -i openstack.py --limit a904e509-b4b1-479e-8137-17bb30b400c9 --check

PLAY \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [setup] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [a904e509-b4b1-479e-8137-17bb30b400c9]

Thanks,  
Govind

---

<div class="post-metadata">

**Author:** ![Govindaraj\_Venkatesa](https://avatars.discourse-cdn.com/v4/letter/g/a698b9/32.png) [@Govindaraj\_Venkatesa](https://forum.ansible.com/u/Govindaraj_Venkatesa)\
**Post date:** [February 17, 2016, 2:49pm UTC](https://forum.ansible.com/t/dynamic-inventory/20596/7 "2016-02-17T14:49:00Z")

</div>

Sorry, it’s the UUID of the machine. Any way we can have it to write IP address?

“mesos\_masters”: [  
“b9d2e61e-0653-4a1f-a472-c5f15a017eae”,  
“ca8c9fc7-337f-4f92-baac-7fe41f6475ce”,  
“a904e509-b4b1-479e-8137-17bb30b400c9”  
],
