# inventory group name variable

**URL:** <https://forum.ansible.com/t/inventory-group-name-variable/25803>\
**Category:** Ansible Project\
**Created:** [October 23, 2017, 12:35pm UTC](https://forum.ansible.com/t/inventory-group-name-variable/25803 "2017-10-23T12:35:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mauricio\_Castro](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@Mauricio\_Castro](https://forum.ansible.com/u/Mauricio_Castro)\
**Post date:** [October 23, 2017, 12:35pm UTC](https://forum.ansible.com/t/inventory-group-name-variable/25803/1 "2017-10-23T12:35:18Z")

</div>

I am kindda new to Ansible and I’ve been trying to find this information everywhere, but I can’t seen to get what I really need, which is:

given a inventory with a group name [xyz] for example, while running ansible with that inventory and pointing to that group specifically like:

> ansible -i my\_inventory xyz -m debug -a “msg=‘the group I am using is {{ ???\_does _this\_variable\_exist\_predefined\_anywhere_??? }}’”

help?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [October 23, 2017, 1:15pm UTC](https://forum.ansible.com/t/inventory-group-name-variable/25803/2 "2017-10-23T13:15:21Z")

</div>

It's not possible to get that information.

---

<div class="post-metadata">

**Author:** ![Mauricio\_Castro](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@Mauricio\_Castro](https://forum.ansible.com/u/Mauricio_Castro)\
**Post date:** [October 23, 2017, 1:27pm UTC](https://forum.ansible.com/t/inventory-group-name-variable/25803/3 "2017-10-23T13:27:08Z")

</div>

Thanks so much Kai, I’ve been eagerly searching these next few moments and found out it’s really nowhere, but good came out of that and I realized I can do a “dynamic inventory” and pass it on as “.py” to -i option of ansible!!! ([http://docs.ansible.com/ansible/latest/intro\_dynamic\_inventory.html](http://docs.ansible.com/ansible/latest/intro_dynamic_inventory.html))

I will try that from the docs and see how it goes: "

```auto
ansible -i openstack.py all -m ping"

this could save my day and add some fun to my inventories.

Thank you for your prompt answer.

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [October 23, 2017, 2:02pm UTC](https://forum.ansible.com/t/inventory-group-name-variable/25803/4 "2017-10-23T14:02:54Z")

</div>

Ansible has hosts and tasks as the primary objects, groups are only  
used in inventory to allow for host selection and convenient variable  
assignment. Once we start task execution, they are just 'labels'  
associated with a host, the variable `group_names` contains all the  
groups of the current host.

Also, hosts are always at least part of 2 groups, one of them being  
'all' (implicit localhost being the exception).
