# how to use facts in group\_vars

**URL:** <https://forum.ansible.com/t/how-to-use-facts-in-group-vars/21409>\
**Category:** Ansible Project\
**Created:** [May 11, 2016, 2:27pm UTC](https://forum.ansible.com/t/how-to-use-facts-in-group-vars/21409 "2016-05-11T14:27:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter\_Horvath1](https://avatars.discourse-cdn.com/v4/letter/p/5f9b8f/32.png) [@Peter\_Horvath1](https://forum.ansible.com/u/Peter_Horvath1)\
**Post date:** [May 11, 2016, 2:27pm UTC](https://forum.ansible.com/t/how-to-use-facts-in-group-vars/21409/1 "2016-05-11T14:27:14Z")

</div>

Hi Guys,

It might be a stupid question, but how can i use facts as variable value in group vars?  
I want to install Elastic search and want to have network.host to be filled automatically with the eth0.ip4 address.

role/template

{% if elasticsearch\_network\_host %}  
network.host: {{ elasticsearch\_network\_host }}  
{% else %}

role/defaults  
elasticsearch\_network\_host: ‘{{ ansible\_eth0[“ipv4”][0][“address”] }}’

group\_vars:  
elasticsearch\_network\_host: ‘{{ ansible\_eth0[“ipv4”][0][“address”] }}’

Is there a way to achieve this?

---

<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:** [May 12, 2016, 9:20pm UTC](https://forum.ansible.com/t/how-to-use-facts-in-group-vars/21409/2 "2016-05-12T21:20:28Z")

</div>

> It might be a stupid question, but how can i use facts as variable value in  
> group vars?

Using facts in group vars is very strange. Which of the hosts in the group would you like to be assign to the group vars.

> I want to install Elastic search and want to have network.host to be filled  
> automatically with the eth0.ip4 address.
> 
> role/template  
> {% if elasticsearch\_network\_host %}  
> network.host: {{ elasticsearch\_network\_host }}  
> {% else %}

So, for each host you would like to add that host ip on eth0 in the Elasticsearch configuration file on that host?

You would achieve that by using this in your role/template  
network.host: {{ ansible\_eth0["ipv4"]["address"] }}
