# Print Hostvar For All Host Under Group

**URL:** <https://forum.ansible.com/t/print-hostvar-for-all-host-under-group/36063>\
**Category:** Ansible Developer\
**Created:** [December 3, 2021, 8:02am UTC](https://forum.ansible.com/t/print-hostvar-for-all-host-under-group/36063 "2021-12-03T08:02:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jitender\_J](https://avatars.discourse-cdn.com/v4/letter/j/2bfe46/32.png) [@Jitender\_J](https://forum.ansible.com/u/Jitender_J)\
**Post date:** [December 3, 2021, 8:02am UTC](https://forum.ansible.com/t/print-hostvar-for-all-host-under-group/36063/1 "2021-12-03T08:02:18Z")

</div>

Hi Team,

Need your help got stuck

I want to use host vars from inventory for all host under a specific group

I tried with the below example but only getting IP when I am passing hostname not getting anything when trying to get ansbile\_host variable value for all host under that group with the group name

ip: “{{hostvars[‘test’][‘ansible\_host’]}}” ------Not working

ip: “{{hostvars[‘test1’][‘ansible\_host’]}}” -------- Working

[test]  
test1 ansible\_host=1.1.1.1  
test2 ansible\_host=2.2.2.2

---

<div class="post-metadata">

**Author:** ![james\_livulpi](https://avatars.discourse-cdn.com/v4/letter/j/77aa72/32.png) [@james\_livulpi](https://forum.ansible.com/u/james_livulpi)\
**Post date:** [December 4, 2021, 11:55pm UTC](https://forum.ansible.com/t/print-hostvar-for-all-host-under-group/36063/2 "2021-12-04T23:55:52Z")

</div>

Hello,

This doesn’t look like its a supported way, you can use index of one and access but not full group:

[https://docs.ansible.com/ansible/latest/reference\_appendices/faq.html#how-do-i-access-a-group-variable](https://docs.ansible.com/ansible/latest/reference_appendices/faq.html#how-do-i-access-a-group-variable)

- Jamer

---

<div class="post-metadata">

**Author:** ![Jitender\_J](https://avatars.discourse-cdn.com/v4/letter/j/2bfe46/32.png) [@Jitender\_J](https://forum.ansible.com/u/Jitender_J)\
**Post date:** [December 6, 2021, 3:42am UTC](https://forum.ansible.com/t/print-hostvar-for-all-host-under-group/36063/3 "2021-12-06T03:42:39Z")

</div>

Thanks …any other way to use hosname wildcard

“{{hostvars[‘_test_’][‘ansible\_host’]}}”

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [December 6, 2021, 4:24pm UTC](https://forum.ansible.com/t/print-hostvar-for-all-host-under-group/36063/4 "2021-12-06T16:24:09Z")

</div>

Is this what you’re looking for?  
$ **cat groupvars-inventory.ini**  
[test]  
test1 ansible\_host=1.1.1.1  
test2 ansible\_host=2.2.2.2

[dev]  
dev1 ansible\_host=3.3.3.3  
dev2 ansible\_host=4.4.4.4

$ **cat groupvars.yml**

---

<div class="post-metadata">

**Author:** ![Jitender\_J](https://avatars.discourse-cdn.com/v4/letter/j/2bfe46/32.png) [@Jitender\_J](https://forum.ansible.com/u/Jitender_J)\
**Post date:** [December 7, 2021, 8:40am UTC](https://forum.ansible.com/t/print-hostvar-for-all-host-under-group/36063/5 "2021-12-07T08:40:50Z")

</div>

Thanks @Todd, First solution is working for me… thank you very much
