Discussion:
[ansible-project] tree/hierarchic structure for inventory?
esco real
2015-07-15 12:01:04 UTC
Permalink
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
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/b41a7c85-dff6-4b51-963d-8ebd57b239e2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Mischa ter Smitten
2015-07-16 20:50:14 UTC
Permalink
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 received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/2830c912-8f7e-46a1-a363-8d77e0d36866%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Paul Markham
2015-07-19 04:01:40 UTC
Permalink
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.
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/2f83e2eb-2d87-41cb-9e12-8717a5ebcfe8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
esco real
2015-07-19 08:08:46 UTC
Permalink
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 ;) ). 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
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/00d7df2c-3bd6-467f-b9d4-9507cf752a27%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Martin
2015-07-21 12:08:08 UTC
Permalink
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 :)

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) :)

/Martin
Post by esco real
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 ;) ). 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
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/00d7df2c-3bd6-467f-b9d4-9507cf752a27%40googlegroups.com
<https://groups.google.com/d/msgid/ansible-project/00d7df2c-3bd6-467f-b9d4-9507cf752a27%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
--
http://www.xing.com/profile/Martin_Marcher
http://www.linkedin.com/in/martinmarcher
Mobil: +43 / 660 / 62 45 103
UID: ATU68801424
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAK1mKEQD7Nc%3DBed8AYkio37yFK6jO43JSssYnit1tF4OhY7uig%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Paul Markham
2015-07-22 04:50:22 UTC
Permalink
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.
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/a9727f0f-a68b-406a-b3df-c9a935e548a1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
esco real
2015-07-22 07:28:28 UTC
Permalink
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
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/094e31e6-7fac-4b7d-bd3a-25b9ebac4153%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Martin
2015-07-22 08:31:30 UTC
Permalink
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 :)

/Martin
Post by esco real
Hello,
[server.atlanta.web]
web1
[server.raleigh.web]
web2
esco
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/094e31e6-7fac-4b7d-bd3a-25b9ebac4153%40googlegroups.com
<https://groups.google.com/d/msgid/ansible-project/094e31e6-7fac-4b7d-bd3a-25b9ebac4153%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
--
http://www.xing.com/profile/Martin_Marcher
http://www.linkedin.com/in/martinmarcher
Mobil: +43 / 660 / 62 45 103
UID: ATU68801424
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAK1mKER_yO%3DQS8o7cP%3DKTvyvpmTsEonrjOhYtMksePFuRD%2BkOw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
esco real
2015-07-29 16:44:28 UTC
Permalink
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
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/c373352b-6be4-4027-ac7a-a252ee04da6a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...