# templates in host\_vars can't use variables from another host

**URL:** <https://forum.ansible.com/t/templates-in-host-vars-cant-use-variables-from-another-host/17358>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [January 22, 2015, 11:48pm UTC](https://forum.ansible.com/t/templates-in-host-vars-cant-use-variables-from-another-host/17358 "2015-01-22T23:48:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Slawomir\_Kowalski](https://avatars.discourse-cdn.com/v4/letter/s/ba8739/32.png) [@Slawomir\_Kowalski](https://forum.ansible.com/u/Slawomir_Kowalski)\
**Post date:** [January 22, 2015, 11:48pm UTC](https://forum.ansible.com/t/templates-in-host-vars-cant-use-variables-from-another-host/17358/1 "2015-01-22T23:48:39Z")

</div>

Hello!

I am currently writing role which is supposed to automate creation of GRE tunnels between endpoints .

So I created new role and it uses variable named gre\_tunnels which is list. It usually looks like this:

gre\_tunnels:

- name: lb1-app1  
ttl: 64  
local:  
addr: “{{lxc\_gre\_ip}}”  
endpoint: “{{ansible\_eth0.ipv4.address}}”  
network: “{{lxc\_subnet}}”  
cidr: “{{lxc\_subnet\_bits}}”  
remote:  
addr: “{{hostvars[‘app1’][‘lxc\_gre\_ip’]}}”  
endpoint: “{{hostvars[‘app1’][‘ansible\_eth0’][‘ipv4’][‘address’]}}”  
network: “{{hostvars[‘app1’][‘lxc\_subnet’]}}”  
cidr: “{{hostvars[‘app1’][‘lxc\_subnet\_bits’]}}”

This role doesn’t do anything particularly fancy, it iterates gre\_tunnels list by means of ‘with\_items’,  
then generates interface definitions for Debian/Ubuntu , brings interfaces up and generates firewall configuration.

My problem is:

I noticed that when I use templates in host\_vars like in example above not all of them are rendered.  
Specifically ‘local’ hash variable values will be correctly presented while ‘remote’ hash values will be rendered incorrectly.  
If I try to use values from this hash in a ‘template’ module variable values look like ‘{#hostvars[‘app1’][‘lxc\_gre\_ip’]#}’ (without quotes).

Problem exists in every ‘{{ }}’ jinja block when hostvars are referenced inside . I’m not sure whether it’s a bug or I am doing something stupid.

My idea of templating in host\_vars is based on assumption that it would be a good idea not to force myself to change IP addresses in multiple places  
( You probably know DRY principle and all that stuff )

So, what should I do next?
