# Dynamic inventory json format question

**URL:** <https://forum.ansible.com/t/dynamic-inventory-json-format-question/27311>\
**Category:** Ansible Project\
**Created:** [April 18, 2018, 6:34am UTC](https://forum.ansible.com/t/dynamic-inventory-json-format-question/27311 "2018-04-18T06:34:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![fseudiba](https://avatars.discourse-cdn.com/v4/letter/f/94ad74/32.png) [@fseudiba](https://forum.ansible.com/u/fseudiba)\
**Post date:** [April 18, 2018, 6:34am UTC](https://forum.ansible.com/t/dynamic-inventory-json-format-question/27311/1 "2018-04-18T06:34:56Z")

</div>

Hello,

in the past i used this inventory entries.

inventory.ini format:

[DATABASE1]  
[hostname1.com](http://hostname1.com)

[DATABASE2]  
[hostname47.de](http://hostname47.de)

dynamic inventory json format:  
{  
“DATABASE1” : { “hosts” : ["[hostname1.com](http://hostname1.com) ] },  
“DATABASE2” : { “hosts” : ["[hostname47.de](http://hostname47.de) ] }  
}

This setup wors fine.

For internal reasons i have to cahneg the format.  
Here is a example that works for me as i expect in inventory.ini format:

[DATABASE1]  
DATABASE1\_hostname1.com ansible\_host=[hostname1.com](http://hostname1.com)

[DATABASE2]  
DATABASE\_2\_hostname47.de ansible\_host=[hostname47.de](http://hostname47.de)

Can please someone give me the eqivalent json format?

Many thanks  
Frank

---

<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:** [April 18, 2018, 2:07pm UTC](https://forum.ansible.com/t/dynamic-inventory-json-format-question/27311/2 "2018-04-18T14:07:53Z")

</div>

My recommendation, is to use the ansible-inventory command to show you what the output should look like:

ansible-inventory -i inventory.ini --list

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [April 18, 2018, 6:08pm UTC](https://forum.ansible.com/t/dynamic-inventory-json-format-question/27311/3 "2018-04-18T18:08:30Z")

</div>

for recreating an inventory: ansible-inventory -i inventory.ini --list  
--export, w/o the --export it just shows a 'flattened view' which is  
what ansible sees internally, good for debugging but not for emulating  
in your own inventory source.

---

<div class="post-metadata">

**Author:** ![fseudiba](https://avatars.discourse-cdn.com/v4/letter/f/94ad74/32.png) [@fseudiba](https://forum.ansible.com/u/fseudiba)\
**Post date:** [April 19, 2018, 6:05am UTC](https://forum.ansible.com/t/dynamic-inventory-json-format-question/27311/4 "2018-04-19T06:05:25Z")

</div>

Hello,

i did a ansible-inventory -i inventory.ini --list against my working inventory.ini and got the following result:

$ ansible-inventory -i inventory.ini --list  
[WARNING]: \* Failed to parse /APPL/ansible/cfg/inventory.ini with ini plugin: /APPL/ansible/cfg/inventory.ini:2: Expected key=value host variable assignment, got: :  
[WARNING]: Unable to parse /APPL/ansible/cfg/inventory.ini as an inventory source  
[WARNING]: No inventory was parsed, only implicit localhost is available  
{  
“\_meta”: {  
“hostvars”: {  
“{”: {  
“ansible\_ssh\_pass”: “xxx”,  
“ansible\_user”: “oracle”  
}  
}  
},  
“all”: {  
“children”: [  
“ungrouped”  
]  
},  
“ungrouped”: {  
“hosts”: [  
“{”  
]  
}  
}

So i still do not know how the the json format should be…  
Frank

---

<div class="post-metadata">

**Author:** ![lambda\_111](https://avatars.discourse-cdn.com/v4/letter/l/4bbf92/32.png) [@lambda\_111](https://forum.ansible.com/u/lambda_111)\
**Post date:** [April 19, 2018, 6:56am UTC](https://forum.ansible.com/t/dynamic-inventory-json-format-question/27311/5 "2018-04-19T06:56:36Z")

</div>

Hi

Can you post contents of your inventory.ini

---

<div class="post-metadata">

**Author:** ![fseudiba](https://avatars.discourse-cdn.com/v4/letter/f/94ad74/32.png) [@fseudiba](https://forum.ansible.com/u/fseudiba)\
**Post date:** [April 19, 2018, 2:03pm UTC](https://forum.ansible.com/t/dynamic-inventory-json-format-question/27311/6 "2018-04-19T14:03:06Z")

</div>

Hello,  
as i did in my question - but here again:

[DATABASE1]  
DATABASE1\_hostname1.com ansible\_host=[hostname1.com](http://hostname1.com)

[DATABASE2]  
DATABASE\_2\_hostname47.de ansible\_host=[hostname47.de](http://hostname47.de)

---

<div class="post-metadata">

**Author:** ![fseudiba](https://avatars.discourse-cdn.com/v4/letter/f/94ad74/32.png) [@fseudiba](https://forum.ansible.com/u/fseudiba)\
**Post date:** [April 19, 2018, 2:16pm UTC](https://forum.ansible.com/t/dynamic-inventory-json-format-question/27311/7 "2018-04-19T14:16:28Z")

</div>

Hello,

ansible-inventory -i inventory.ini --list worked now fine for me.  
(I had a typo in the inventory.ini which prevented ansible-Inventory … --list from working in the correct way).  
Many tnaks for all your help!  
Frank
