# Bug/limitation with hosts in multiple groups

**URL:** <https://forum.ansible.com/t/bug-limitation-with-hosts-in-multiple-groups/11548>\
**Category:** Ansible Project\
**Created:** [May 15, 2012, 8:11am UTC](https://forum.ansible.com/t/bug-limitation-with-hosts-in-multiple-groups/11548 "2012-05-15T08:11:17Z")\
**Posts on this page:** 5\
**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 15, 2012, 8:11am UTC](https://forum.ansible.com/t/bug-limitation-with-hosts-in-multiple-groups/11548/1 "2012-05-15T08:11:17Z")

</div>

Hi,

I've not been playing with Ansible for long so I may just be  
misunderstanding how it's supposed to be used. However, it seems that  
there's an issue when a single host is included in multiple groups in  
a hosts .ini style inventory (I haven't tested a YAML inventory yet).

Say I have the following:

&nbsp;&nbsp;&nbsp;&nbsp;[example:vars]  
&nbsp;&nbsp;&nbsp;&nbsp;domain\_name=example.com

&nbsp;&nbsp;&nbsp;&nbsp;[example]  
&nbsp;&nbsp;&nbsp;&nbsp;example-web  
&nbsp;&nbsp;&nbsp;&nbsp;example-db

&nbsp;&nbsp;&nbsp;&nbsp;[example-web]  
&nbsp;&nbsp;&nbsp;&nbsp;10.0.3.82

&nbsp;&nbsp;&nbsp;&nbsp;[example-db]  
&nbsp;&nbsp;&nbsp;&nbsp;10.0.3.82

In case it helps, for the 'example' group I want the host, 10.0.3.82,  
to be configured to handle the web \*and\* db roles. Another version of  
this might split web/db between across different hosts.

When the 'setup' command is run on 10.0.3.82, /etc/ansible/setup is  
written as expected but 'group\_names' is missing the 'example-db'  
group:

&nbsp;&nbsp;&nbsp;&nbsp;"group\_names": [  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"example",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"example-web"  
&nbsp;&nbsp;&nbsp;&nbsp;]

If I reverse the order of the -web and -db group definitions in the  
hosts inventory then 'setup' emits example-db in place of example-web:

&nbsp;&nbsp;&nbsp;&nbsp;"group\_names": [  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"example",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"example-db"  
&nbsp;&nbsp;&nbsp;&nbsp;]

So, am am I doing something daft or should I submit this as an issue?

Thanks, 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 15, 2012, 8:16am UTC](https://forum.ansible.com/t/bug-limitation-with-hosts-in-multiple-groups/11548/2 "2012-05-15T08:16:14Z")

</div>

Oh, and also ...

If the same host, 10.0.3.82, is also listed at the top of the file,  
outside of any group definitions, then it only appears in the  
'ungrouped' group name and any actual groups, as well as those groups'  
vars, are ignored.

It might seem weird to even try that, but I wanted to assign a  
variable to just that host and didn't want to repeat myself my adding  
the variable everytime the host is mentioned.

- 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 15, 2012, 10:52am UTC](https://forum.ansible.com/t/bug-limitation-with-hosts-in-multiple-groups/11548/3 "2012-05-15T10:52:00Z")

</div>

> When the 'setup' command is run on 10.0.3.82, /etc/ansible/setup is  
> written as expected but 'group\_names' is missing the 'example-db'  
> group:

interesting.

> "group\_names": [  
> "example",  
> "example-web"  
> ]
> 
> If I reverse the order of the -web and -db group definitions in the  
> hosts inventory then 'setup' emits example-db in place of example-web:
> 
> "group\_names": [  
> "example",  
> "example-db"  
> ]

Please submit it. It may not get fixed in 0.4, though it will be  
definitely fixed in 0.5

Would be worthwhile to test if you have the same problem with the YAML  
inventory format or not.

--Michael

---

<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 15, 2012, 10:52am UTC](https://forum.ansible.com/t/bug-limitation-with-hosts-in-multiple-groups/11548/4 "2012-05-15T10:52:51Z")

</div>

It seems that the code is probably just not supporting multiple groups  
per host in the INI format very well yet, if you see that.

Ungrouped works like any another group, more or less.

---

<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 15, 2012, 1:43pm UTC](https://forum.ansible.com/t/bug-limitation-with-hosts-in-multiple-groups/11548/5 "2012-05-15T13:43:27Z")

</div>

> Please submit it. It may not get fixed in 0.4, though it will be  
> definitely fixed in 0.5

Just submitted two issues:

#394 setup command does not include all groups for host  
#395 ungrouped host ignores groups it also belongs to

> From what you say, they're probably the same thing but they seem like

two nice, distinct test cases, especially with per-host vars attached.

Cheers, Matt
