# Potential bug/solution with Inventory.groups\_list()

**URL:** <https://forum.ansible.com/t/potential-bug-solution-with-inventory-groups-list/14994>\
**Category:** Ansible Developer\
**Created:** [April 11, 2014, 2:20am UTC](https://forum.ansible.com/t/potential-bug-solution-with-inventory-groups-list/14994 "2014-04-11T02:20:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Taylor\_Barstow](https://avatars.discourse-cdn.com/v4/letter/t/6a8cbe/32.png) [@Taylor\_Barstow](https://forum.ansible.com/u/Taylor_Barstow)\
**Post date:** [April 11, 2014, 2:20am UTC](https://forum.ansible.com/t/potential-bug-solution-with-inventory-groups-list/14994/1 "2014-04-11T02:20:30Z")

</div>

Hello list!

I think I have found a bug which causes the magic “groups” variable to contain duplicate host names (same name multiple times in a single group), when using an inventory directory (-i dirname).

I read the code a bit, and it appears the magic “groups” variable contains the output of Inventory.groups\_list(). So made a simple test case using the existing inventory dir test fixture to show Inventory.groups\_list() returning duplicates. Here is my commit (on top of HEAD as of an hour ago):

[https://github.com/taylorbarstow/ansible/commit/ffbae34159eff3cd2e7527ab372a35294a9ed549](https://github.com/taylorbarstow/ansible/commit/ffbae34159eff3cd2e7527ab372a35294a9ed549)

And here is the relevant snippet of my (failing) test output:

INVENTORY groups\_list[‘all’]=[‘morpheus’, ‘morpheus’, ‘morpheus’, ‘thor’, ‘thor’, ‘thor’, ‘zeus’, ‘zeus’, ‘zeus’]  
EXPECTED groups\_list[‘all’]=[‘morpheus’, ‘thor’, ‘zeus’]  
INVENTORY groups\_list[‘major-god’]=[‘thor’, ‘thor’, ‘zeus’, ‘zeus’]  
EXPECTED groups\_list[‘major-god’]=[‘thor’, ‘zeus’]  
INVENTORY groups\_list[‘norse’]=[‘thor’, ‘thor’]  
EXPECTED groups\_list[‘norse’]=[‘thor’]  
INVENTORY groups\_list[‘minor-god’]=[‘morpheus’, ‘morpheus’]  
EXPECTED groups\_list[‘minor-god’]=[‘morpheus’]  
INVENTORY groups\_list[‘ungrouped’]=[‘morpheus’, ‘thor’, ‘zeus’]  
EXPECTED groups\_list[‘ungrouped’]=  
INVENTORY groups\_list[‘greek’]=[‘morpheus’, ‘morpheus’, ‘zeus’, ‘zeus’]

EXPECTED groups\_list[‘greek’]=[‘morpheus’, ‘zeus’]

I am not 100% sure that I have understood ‘ungrouped’ correctly (should it actually be empty?) – but that is besides the point, I think you will agree that the groups\_list output above does not look right with all those duplicate hostnames.

I’m new to ansible. Would anyone be willing to give me a hand validating this issue? Do you agree that it is a problem? Can you reproduce the failure of that test case / output in your environment?

Finally, I have some ideas for a potential resolution, but how long can this email really get? If people agree this is a bug, I’ll open an issue / PR in github.

Thank you in advance! Ansible is awesome!  
Taylor

---

<div class="post-metadata">

**Author:** ![willthames](https://avatars.discourse-cdn.com/v4/letter/w/8dc957/32.png) [@willthames](https://forum.ansible.com/u/willthames)\
**Post date:** [April 12, 2014, 4:09am UTC](https://forum.ansible.com/t/potential-bug-solution-with-inventory-groups-list/14994/2 "2014-04-12T04:09:42Z")

</div>

Might be worth checking with Serge whether his PR fixes this or not ([https://github.com/ansible/ansible/pull/6734](https://github.com/ansible/ansible/pull/6734)) as he’s doing _a lot_ of work in that area of code (and if it’s not, he might be able to shed some light on this)

Will

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [April 12, 2014, 8:30am UTC](https://forum.ansible.com/t/potential-bug-solution-with-inventory-groups-list/14994/3 "2014-04-12T08:30:58Z")

</div>

Hi Taylor,

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [April 13, 2014, 11:17pm UTC](https://forum.ansible.com/t/potential-bug-solution-with-inventory-groups-list/14994/4 "2014-04-13T23:17:14Z")

</div>

“I still need to actually add some additional unit tests to reflect the modifications I made. I was going to address that after the PR would get merged, but maybe better to not wait.”

Please just go ahead and update the PR. Thanks!

---

<div class="post-metadata">

**Author:** ![Taylor\_Barstow](https://avatars.discourse-cdn.com/v4/letter/t/6a8cbe/32.png) [@Taylor\_Barstow](https://forum.ansible.com/u/Taylor_Barstow)\
**Post date:** [April 13, 2014, 11:48pm UTC](https://forum.ansible.com/t/potential-bug-solution-with-inventory-groups-list/14994/5 "2014-04-13T23:48:48Z")

</div>

Hi all,

Thanks for the responses! FYI, I continued the discussion with Serge on his PR, including a few more test cases:

[https://github.com/ansible/ansible/pull/6379](https://github.com/ansible/ansible/pull/6379)

Taylor
