# Odd global variable substitition behavior

**URL:** <https://forum.ansible.com/t/odd-global-variable-substitition-behavior/14831>\
**Category:** Ansible Project\
**Created:** [March 22, 2014, 6:01pm UTC](https://forum.ansible.com/t/odd-global-variable-substitition-behavior/14831 "2014-03-22T18:01:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aaron\_Hunter](https://avatars.discourse-cdn.com/v4/letter/a/e19adc/32.png) [@Aaron\_Hunter](https://forum.ansible.com/u/Aaron_Hunter)\
**Post date:** [March 22, 2014, 6:01pm UTC](https://forum.ansible.com/t/odd-global-variable-substitition-behavior/14831/1 "2014-03-22T18:01:40Z")

</div>

I’m trying to do something complex with variables that allows me to auto-generate kickstart files for the VMs in my inventory. It almost works but I’m getting an odd error. The variables are spread across multiple files so here is an example:

group\_vars/all  
prod\_vlan12\_network\_gateway: 192.168.12.1

host\_vars/host.domain.com  
default\_gateway: “{{ prod\_vlan12\_network\_gateway }}”

(The host variable references the global one, DRY style.)

role/kickstart  
I have a template in this role that references the host variable like this: {{ hostvars[item][‘default\_gateway’] }}  
where item comes from a: “with\_items: groups[‘vms’]” statement in the role’s task file

The overall pattern works fine except in this case where the host variable references a global one. In this case the template output is, “{{ prod\_vlan12\_network\_gateway }}” rather than the expected “192.168.12.1”. In cases where the host variable is defined directly, e.g. “vcpus: 2”, it works fine.

I do this to avoid repeating data like the gateway IP address multiple times. Is there a Jinja trick or something else I can try to get it resolve these nested variables?

Thanks,  
Aaron
