# hosts vs groups ini-style config

**URL:** <https://forum.ansible.com/t/hosts-vs-groups-ini-style-config/11563>\
**Category:** Ansible Project\
**Created:** [May 19, 2012, 10:05pm UTC](https://forum.ansible.com/t/hosts-vs-groups-ini-style-config/11563 "2012-05-19T22:05:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt\_Goodall](https://avatars.discourse-cdn.com/v4/letter/m/eb8c5e/32.png) [@Matt\_Goodall](https://forum.ansible.com/u/Matt_Goodall)\
**Post date:** [May 19, 2012, 10:05pm UTC](https://forum.ansible.com/t/hosts-vs-groups-ini-style-config/11563/1 "2012-05-19T22:05:50Z")

</div>

Hi,

I realise I'm very new to this project, so I put on my flame-proof  
jacket before posting this ;-), but I \*believe\* the .ini style  
inventory can be simplified and perhaps made a little more consistent.

It seems to me that the inventory is really just a graph of nodes,  
where each node is basically a name and a set of variables. Doesn't  
that mean that a host is really just a node with no children and a  
group is a node with children?

Given that assumption, does it actually make sense to differentiate a  
group of hosts:

&nbsp;&nbsp;&nbsp;&nbsp;[g1]  
&nbsp;&nbsp;&nbsp;&nbsp;h1  
&nbsp;&nbsp;&nbsp;&nbsp;h2

> From a group of groups:

&nbsp;&nbsp;&nbsp;&nbsp;[g1:children]  
&nbsp;&nbsp;&nbsp;&nbsp;g2

&nbsp;&nbsp;&nbsp;&nbsp;[g2]  
&nbsp;&nbsp;&nbsp;&nbsp;h3

Couldn't this be simplified right down to:

&nbsp;&nbsp;&nbsp;&nbsp;[g1]  
&nbsp;&nbsp;&nbsp;&nbsp;h1  
&nbsp;&nbsp;&nbsp;&nbsp;h2  
&nbsp;&nbsp;&nbsp;&nbsp;g2

&nbsp;&nbsp;&nbsp;&nbsp;[g2]  
&nbsp;&nbsp;&nbsp;&nbsp;h3

This actually works quite nicely with vars too. For example if I have  
lots of vars for a particular host, I would now have the option to use  
a [:vars] block for a host as is currently possible for a group  
instead of a long line of text:

&nbsp;&nbsp;&nbsp;&nbsp;[g1]  
&nbsp;&nbsp;&nbsp;&nbsp;h1

&nbsp;&nbsp;&nbsp;&nbsp;[g1:vars]  
&nbsp;&nbsp;&nbsp;&nbsp;a=1

&nbsp;&nbsp;&nbsp;&nbsp;[h1:vars]  
&nbsp;&nbsp;&nbsp;&nbsp;b=2  
&nbsp;&nbsp;&nbsp;&nbsp;c=3  
&nbsp;&nbsp;&nbsp;&nbsp;...  
&nbsp;&nbsp;&nbsp;&nbsp;z=26

I think the only downside to this is that you could accidentally end  
up with something that was supposed to be a group but has no children,  
and a node with no children is considered a host. However, I would  
suggest that you didn't mean to have a group with no children, so it  
should be removed (or commented out at the least).

If you're interested in this idea, and I won't be offended it you're  
not, then I have a working .ini parser that builds the graph of nodes,  
including support for vars, host ports, etc that I would be happy to  
share or even try to wire in to Ansible myself.

- Matt

---

<div class="post-metadata">

**Author:** ![Matt\_Goodall](https://avatars.discourse-cdn.com/v4/letter/m/eb8c5e/32.png) [@Matt\_Goodall](https://forum.ansible.com/u/Matt_Goodall)\
**Post date:** [May 19, 2012, 10:23pm UTC](https://forum.ansible.com/t/hosts-vs-groups-ini-style-config/11563/2 "2012-05-19T22:23:04Z")

</div>

> Hi,
> 
> I realise I'm very new to this project, so I put on my flame-proof  
> jacket before posting this ;-), but I \*believe\* the .ini style  
> inventory can be simplified and perhaps made a little more consistent.
> 
> It seems to me that the inventory is really just a graph of nodes,  
> where each node is basically a name and a set of variables. Doesn't  
> that mean that a host is really just a node with no children and a  
> group is a node with children?

[...]

> If you're interested in this idea, and I won't be offended it you're  
> not, then I have a working .ini parser that builds the graph of nodes,  
> including support for vars, host ports, etc that I would be happy to  
> share or even try to wire in to Ansible myself.

Here you go, [https://gist.github.com/2732574](https://gist.github.com/2732574).

- Matt

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [May 19, 2012, 11:02pm UTC](https://forum.ansible.com/t/hosts-vs-groups-ini-style-config/11563/3 "2012-05-19T23:02:22Z")

</div>

Well, that would imply a host name and a group name couldn't be the same, right? It is very unlikely but it would be ambiguous in that case.

Otherwise I would agree.

-- Michael

---

<div class="post-metadata">

**Author:** ![Matt\_Goodall](https://avatars.discourse-cdn.com/v4/letter/m/eb8c5e/32.png) [@Matt\_Goodall](https://forum.ansible.com/u/Matt_Goodall)\
**Post date:** [May 19, 2012, 11:12pm UTC](https://forum.ansible.com/t/hosts-vs-groups-ini-style-config/11563/4 "2012-05-19T23:12:57Z")

</div>

> Well, that would imply a host name and a group name couldn't be the same, right? It is very unlikely but it would be ambiguous in that case.

Yeah, that's true. I'm struggling to come up with a scenario where I  
would ever name a host and group the same, but anything's possible.

> Otherwise I would agree.

OK, have a sleep on it in case you think of anything else. If you want  
me to have a play to see how it works out in practice then let me  
know, or just grab the code and try it yourself.

Thanks for listening :).

- Matt

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [May 20, 2012, 11:43am UTC](https://forum.ansible.com/t/hosts-vs-groups-ini-style-config/11563/5 "2012-05-20T11:43:32Z")

</div>

We're going to keep the 'children' syntax.

A few other reasons.

If you end up typo'ing a group name, you would end up creating a host, which would be confusing.

I am pretty sure I like things being explicit, and not mixing hosts and groups, since the file is easier to audit that way to see  
if it is what you want it to be.

---

<div class="post-metadata">

**Author:** ![Matt\_Goodall](https://avatars.discourse-cdn.com/v4/letter/m/eb8c5e/32.png) [@Matt\_Goodall](https://forum.ansible.com/u/Matt_Goodall)\
**Post date:** [May 20, 2012, 1:30pm UTC](https://forum.ansible.com/t/hosts-vs-groups-ini-style-config/11563/6 "2012-05-20T13:30:59Z")

</div>

> > \> Well, that would imply a host name and a group name couldn't be the same, right? It is very unlikely but it would be ambiguous in that case.
> > 
> > Yeah, that's true. I'm struggling to come up with a scenario where I  
> > would ever name a host and group the same, but anything's possible.
> 
> We're going to keep the 'children' syntax.
> 
> A few other reasons.
> 
> If you end up typo'ing a group name, you would end up creating a host, which would be confusing.

Hmm, it's probably worth me mentioning that I have already  
accidentally added a group to a non [:children] section and had the  
exact problem you mention above - a group mistaken as a host. Not a  
typo, but an easy enough mistake to make and took me a while to spot.

I've also tried to add a host to a [:children] section, but that does  
at least give a decent enough error message IIRC.

I'm sure I'll get used to where to put things soon ;).

> I am pretty sure I like things being explicit, and not mixing hosts and groups, since the file is easier to audit that way to see  
> if it is what you want it to be.

I like having anything in a group in one list, but that's clearly a  
subjective preference.

OK, one more suggestion and then I promise to shut up ;), but if  
you're aiming for explicit, perhaps [:children] is a little vague?  
Maybe something like [:groups] would be better?

- Matt

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [May 20, 2012, 1:52pm UTC](https://forum.ansible.com/t/hosts-vs-groups-ini-style-config/11563/7 "2012-05-20T13:52:30Z")

</div>

> OK, one more suggestion and then I promise to shut up ;), but if  
> you're aiming for explicit, perhaps [:children] is a little vague?  
> Maybe something like [:groups] would be better?

Implicit vs Explicit is different than bike shedding the word choice 🙂

Subgroups is probably technically most accurate, though it's already established and I don't want the code littered with synonym logic.

--Michael
