is nested yaml inventory file for ansible supported?

2,912 views
Skip to first unread message

vinod kumar

unread,
Mar 31, 2017, 7:53:26 AM3/31/17
to Ansible Development
Hi Guys,

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

- prod:
    webserver:
      hosts:
        example1.com
    db_servers:
      hosts:
        example2.com
        example3.com
- stag:
    webserver:
      hosts:
        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!

Matt Martz

unread,
Mar 31, 2017, 8:01:26 AM3/31/17
to Ansible Development, vinod kumar
There is an example yaml inventory on github explaining the structure.  You can find it at:


--
You received this message because you are subscribed to the Google Groups "Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-deve...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Matt Martz
@sivel
sivel.net

Milo Minderbinder

unread,
Mar 31, 2017, 10:24:57 AM3/31/17
to Ansible Development
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:
---

all:
 children:
   prod:
     children:
       webserver:
         hosts:
           example1.com:
       db_servers:
         hosts:
           example2.com:
           example3.com:
   stag:
     children:
       webserver:
         hosts:
           example3.com:

vinod kumar

unread,
Apr 3, 2017, 6:10:45 AM4/3/17
to Ansible Development
Thanks Matt and Milo, we have tried Milo way of inventory file, it works...everything is key now!

vinod kumar

unread,
Apr 3, 2017, 8:09:09 AM4/3/17
to Ansible Development
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

---

all:

  children:

    prod:

      children:

        webserver:

          hosts:

            example1.com:

        dbserver:

          hosts:

            example2.com

    stag:

      children:

        webserver:

          hosts:

            example3.com

        dbserver:

          hosts:

            example4.com

 

 

ubuntu@ubuntu:~$ ansible --list-host -i inv all

  hosts (12):

    ---

    all:

    children:

    prod:

    webserver:

    hosts:

    example1.com:

    dbserver:

    example2.com

    stag:

    example3.com

    example4.com

 

 

 

suse-host:~  # ansible --list-host -i inv all

  hosts (4):

    example3.com

    example1.com

    example4.com

    example2.com



On Friday, 31 March 2017 19:54:57 UTC+5:30, Milo Minderbinder wrote:

bc...@redhat.com

unread,
Mar 2, 2018, 12:18:52 PM3/2/18
to Ansible Development
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.
Reply all
Reply to author
Forward
0 new messages