# Getting variables defined in group\_vars

**URL:** <https://forum.ansible.com/t/getting-variables-defined-in-group-vars/18157>\
**Category:** Ansible Project\
**Created:** [May 5, 2015, 10:55am UTC](https://forum.ansible.com/t/getting-variables-defined-in-group-vars/18157 "2015-05-05T10:55:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ivan\_Kurnosov](https://avatars.discourse-cdn.com/v4/letter/i/ed8c4c/32.png) [@Ivan\_Kurnosov](https://forum.ansible.com/u/Ivan_Kurnosov)\
**Post date:** [May 5, 2015, 10:55am UTC](https://forum.ansible.com/t/getting-variables-defined-in-group-vars/18157/1 "2015-05-05T10:55:22Z")

</div>

Hi,

is it possible to retrieve variables defined per host with all group\_vars and host\_vars definitions applied?

The case:

let’s say we have a task to configure an haproxy instance.

In its config file template we iterate over servers in the `webserver` group and need to retrieve the `httpd_port` variable that might be defined in either some of `group_vars` or `host_vars`.

So for a particular server it might be a specific setting in `host_vars/hostname` or a generic one from `group_vars/webserver`

How would you resolve it?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [May 5, 2015, 12:48pm UTC](https://forum.ansible.com/t/getting-variables-defined-in-group-vars/18157/2 "2015-05-05T12:48:59Z")

</div>

These will all be merged in, so you'll have httpd\_port available as  
the result of that merge. host vars will overrite group vars so this  
should work as you want it.

---

<div class="post-metadata">

**Author:** ![jack.martin8912](https://avatars.discourse-cdn.com/v4/letter/j/7ba0ec/32.png) [@jack.martin8912](https://forum.ansible.com/u/jack.martin8912)\
**Post date:** [May 5, 2015, 4:01pm UTC](https://forum.ansible.com/t/getting-variables-defined-in-group-vars/18157/3 "2015-05-05T16:01:53Z")

</div>

Use the debug module and print out the value of httpd\_port when running over some or all of your servers. You can do this with an ad-hoc command like:

ansible all -m debug -a ‘msg=“Port is {{ httpd\_port }}”’
