# is nested yaml inventory file for ansible supported?

**URL:** <https://forum.ansible.com/t/is-nested-yaml-inventory-file-for-ansible-supported/24115>\
**Category:** Ansible Developer\
**Created:** [March 31, 2017, 11:53am UTC](https://forum.ansible.com/t/is-nested-yaml-inventory-file-for-ansible-supported/24115 "2017-03-31T11:53:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vinod\_kumar4](https://avatars.discourse-cdn.com/v4/letter/v/779978/32.png) [@vinod\_kumar4](https://forum.ansible.com/u/vinod_kumar4)\
**Post date:** [March 31, 2017, 11:53am UTC](https://forum.ansible.com/t/is-nested-yaml-inventory-file-for-ansible-supported/24115/1 "2017-03-31T11:53:26Z")

</div>

Hi Guys,

I’m trying to use a yaml file as inventory file which looks like below:

- prod:  
webserver:  
hosts:  
[example1.com](http://example1.com)  
db\_servers:  
hosts:  
[example2.com](http://example2.com)  
[example3.com](http://example3.com)
- stag:  
webserver:  
hosts:  
[example3.com](http://example3.com)

It doesn’t seem to work, and I couldn’t find much info on ansible docs around yaml inventory file.  
Please let me if above yaml works as inventory file in any ansible version ?.. thanks in advance!

---

<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:** [March 31, 2017, 12:01pm UTC](https://forum.ansible.com/t/is-nested-yaml-inventory-file-for-ansible-supported/24115/2 "2017-03-31T12:01:13Z")

</div>

There is an example yaml inventory on github explaining the structure. You can find it at:

[https://github.com/ansible/ansible/blob/devel/examples/hosts.yaml](https://github.com/ansible/ansible/blob/devel/examples/hosts.yaml)

---

<div class="post-metadata">

**Author:** ![Milo\_Minderbinder](https://avatars.discourse-cdn.com/v4/letter/m/ecb155/32.png) [@Milo\_Minderbinder](https://forum.ansible.com/u/Milo_Minderbinder)\
**Post date:** [March 31, 2017, 2:24pm UTC](https://forum.ansible.com/t/is-nested-yaml-inventory-file-for-ansible-supported/24115/3 "2017-03-31T14:24:56Z")

</div>

Specifically, note from the example Matt provided that all values in the YAML inventory file are map values, never lists. So the - (dash) preceding your “prod” and “stag” groups should be removed. Also note that all hosts listed under a “host:” mapping are also mapping values, so must end with a colon. Finally, groups which are children of other groups should be listed under the “children:” mapping under the parent group. So your example should look like:

`

---

<div class="post-metadata">

**Author:** ![vinod\_kumar4](https://avatars.discourse-cdn.com/v4/letter/v/779978/32.png) [@vinod\_kumar4](https://forum.ansible.com/u/vinod_kumar4)\
**Post date:** [April 3, 2017, 10:10am UTC](https://forum.ansible.com/t/is-nested-yaml-inventory-file-for-ansible-supported/24115/4 "2017-04-03T10:10:45Z")

</div>

Thanks Matt and Milo, we have tried Milo way of inventory file, it works…everything is key now!

---

<div class="post-metadata">

**Author:** ![vinod\_kumar4](https://avatars.discourse-cdn.com/v4/letter/v/779978/32.png) [@vinod\_kumar4](https://forum.ansible.com/u/vinod_kumar4)\
**Post date:** [April 3, 2017, 12:09pm UTC](https://forum.ansible.com/t/is-nested-yaml-inventory-file-for-ansible-supported/24115/5 "2017-04-03T12:09:08Z")

</div>

Hi Milo,

It does work in SLES system but doesn’t work in Ubuntu system.  
In ubuntu, it lists every key in yaml file

Below are the sample example for the same:

vi inv

---

<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:** [March 2, 2018, 5:18pm UTC](https://forum.ansible.com/t/is-nested-yaml-inventory-file-for-ansible-supported/24115/6 "2018-03-02T17:18:52Z")

</div>

This does not look like a platform problem, probably due to using a different configuration.

The ubuntu machine is parsing the file using the ‘ini’ format, the suse is using the yaml format.

Use -vvv to get more info on why that is happening, you are probably getting errors or warnings or have the systems with non default configurations.
