# dynamic inventory and --list printing the groupname

**URL:** <https://forum.ansible.com/t/dynamic-inventory-and-list-printing-the-groupname/14529>\
**Category:** Ansible Project\
**Created:** [February 9, 2014, 7:33pm UTC](https://forum.ansible.com/t/dynamic-inventory-and-list-printing-the-groupname/14529 "2014-02-09T19:33:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![habeeb\_rahman](https://avatars.discourse-cdn.com/v4/letter/h/ce7236/32.png) [@habeeb\_rahman](https://forum.ansible.com/u/habeeb_rahman)\
**Post date:** [February 9, 2014, 7:33pm UTC](https://forum.ansible.com/t/dynamic-inventory-and-list-printing-the-groupname/14529/1 "2014-02-09T19:33:39Z")

</div>

Hi Ansiblers,

I just finished a python program to query our mysql inventory.  
when I do python getinv.py --list, i can see the json output. And ‘ansible us-east-1\_app1 --list-hosts’ works as well.  
The only problem is it also displays the group name in the output. This affects when I check say uptime - ssh says not able to ssh to the **group name.**  
eg,  
$\>ansible **us-east-1\_app1** --list-hosts

**us-east-1\_app1**  
app000ea2  
app002ea1

Any idea why ansible also gets the **group name**?  
Here is the json part…

“ **us-east-1\_app1** ”: {  
“children”: [  
“app1”  
]  
},

“app1”: {  
“hosts”: [  
“app000ea1”,  
“app002ea2”  
]  
},

Any pointers?

---

<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:** [February 9, 2014, 9:19pm UTC](https://forum.ansible.com/t/dynamic-inventory-and-list-printing-the-groupname/14529/2 "2014-02-09T21:19:03Z")

</div>

Can you please show the full output from the list command?

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [February 9, 2014, 9:20pm UTC](https://forum.ansible.com/t/dynamic-inventory-and-list-printing-the-groupname/14529/3 "2014-02-09T21:20:37Z")

</div>

When creating a dynamic inventory plugin, if you don’t intend on actually putting hosts directly in the group, you still need to include the ‘hosts’ key to the group with an empty list.

Such as:

“us-east-1\_app1”: {  
“children”: [  
“app1”  
,]  
“hosts”:   
},

“app1”: {  
“hosts”: [  
“app000ea1”,  
“app002ea2”  
]  
},

Not doing so, basically has the outcome that you describe. Ansible assumes that you mean that ‘us-east1\_app1’ is to be an ungrouped host.

---

<div class="post-metadata">

**Author:** ![mihai-satmarean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mihai-satmarean/32/1843_2.png) [@mihai-satmarean](https://forum.ansible.com/u/mihai-satmarean)\
**Post date:** [March 8, 2017, 4:06pm UTC](https://forum.ansible.com/t/dynamic-inventory-and-list-printing-the-groupname/14529/4 "2017-03-08T16:06:47Z")

</div>

Hi, Can you share the script in a way, we are looking for ways to do the same.  
Thanks!

duminică, 9 februarie 2014, 20:33:39 UTC+1, habeeb rahman a scris:
