tree/hierarchic structure for inventory?

Hello,

I would like to discuss the idea for a hierarchic structure for the inventory. Would it possible to support something like that?

For example with this structure:

server
– atlanta
-- web –hosts:web1
– raleigh
-- web – host:web2

You would need this config:
{
“web” : { “hosts”: [ “web1”, “web2” ] },
“server” : { “hosts”: [ “web1”, “web2” ] },
“atlanta” : { “hosts”: [ “web1” ] },
“raleigh” : { “hosts”: [ “web2” ] }
}

To work with “children” the group names would have to be unique in the whole tree. So “web” would break this up.

Wouldn’t it be nice to use something like that?
{
“server”
{ “atlanta” { “web” {“hosts”: [ “web1” ] } } },
{ “raleigh” { “web” {“hosts”: [ “web2” ] } } }
}

I came up with this by using a KeePass database as inventory source:
https://github.com/escoreal/ansible_kdb_inventory
Here I have to build the tree for each host and add it to all parents. But this doesn’t scale to well.

Thanks,
esco

We are working on the same problem. Right know we are using a custom piece of python code with nested dicts to represent our group and return them as json.

You can write a dynamic inventory script which allows you to specify the inventory in another format, or fetch it from a configuration management database.

I’m not sure if this is exactly what you want, but I wrote one that lets you specify servers and which parent groups they belong in; basically the inverse of the normal inventory. The code is here https://github.com/pmarkham/ansible-inventory-inverted.

Hello Paul,

yes, I did likely the same but used a KeePass 2 database instead of an ini file as inventory source. So here we have similar thoughts (if you are using KeePass 2 you should try my script :wink: ). Adding each host to his parents is possible. But apart from the scaling problem you would have trouble with group_vars for non unique group names in different branches. And I guess there are a lot more users which manage their inventory as tree.

esco

Hi Paul,

I think the inverted inventory is a great idea.

IIRC clusterssh went from a format that was similiar to the “normal” ansible inventory to something like this:

node1 group1,group2,group3
node2 group3
node3 group1,group3

I think that this is a more natural way of specifying it rather than the sectioning of ini files. The group_vars/group1, group_vars/group2, … files (or dirs) could be used to specify common attributes, the dynamic inventory script could read these and output just the right information :slight_smile:

Of course this create yet another config file format but that is just because I’m comparing to a tool where I found the inventory management to be somewhat working. When dealing with manual inventory management (of course going for larger numbers of servers nothing beats an actuall automated inventory) :slight_smile:

/Martin

Hi Martin,

I originally had the inventory in yaml format, but changed to ini format for some reason (which I can’t remember). The clusterssh format would work well if you just wanted the host and group relationships, but I also wanted to support host and group variables like the default static inventory format does.

Ideally a CMDB of some sort would be used, but we don’t have one so we need to maintain a manual inventory.

Fortunately they’ve made it flexible enough to support whatever format you want to use; I’m currently playing with getting the inventory from etcd so we can dynamically add and remove hosts.

Hello,

to build a tree with ini format I think something like that could be used:

[server.atlanta.web]
web1

[server.raleigh.web]

web2

esco

Hi,

yes the host and group variables are the most important thing and I’d personally go and separate them out to the group_vars/… and host_vars/… directories. That is just a matter preference.

I have no emotional attachement to the the file format. I’m just saying that I saw this format working and it was working very convenient to work with.

I think a large part of the way will be discussing this as it is nearly infinitely more complicated to create something that is then very simple to use :slight_smile:

/Martin

Hello Martin,

you are right. Supporting a tree structure for this with plain files/directories (group_vars…) wouldn’t be that nice. And it is very sensible at the moment.

But I made this work for me by resolving the group_vars in the tree directly to host_vars. So group names don’t have to be unique in the inventory. And now I am very happy with the combination of Ansible and KeePass…

esco

If someone is interested in this topic:
Now, I use the name and the UUID of the groups (name_uuid) to build up the tree (children, group_vars…). So group names don’t have to be unique and performance and scaling isn’t a problem anymore…

If you use a CMDB your groups usually would have some IDs, too.

esco

If someone come up with a solution (like a dynamic inventory script that reads some inverted inventory dsl), please share, I would be very interested!
I see the need for such inverted inventory in the case, where I have a lot of interconnected services, where number of services is really large. This is how hadoop environment looks like with tens of different services.
Thanks,
Krzysztof

W dniu poniedziałek, 7 września 2015 21:10:15 UTC+2 użytkownik esco real napisał: