# variable inheritance as dict within template

**URL:** <https://forum.ansible.com/t/variable-inheritance-as-dict-within-template/15574>\
**Category:** Ansible Project\
**Created:** [June 29, 2014, 8:52pm UTC](https://forum.ansible.com/t/variable-inheritance-as-dict-within-template/15574 "2014-06-29T20:52:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt\_Peterson](https://avatars.discourse-cdn.com/v4/letter/m/3e96dc/32.png) [@Matt\_Peterson](https://forum.ansible.com/u/Matt_Peterson)\
**Post date:** [June 29, 2014, 8:52pm UTC](https://forum.ansible.com/t/variable-inheritance-as-dict-within-template/15574/1 "2014-06-29T20:52:43Z")

</div>

Howdy,

It appears that most variables and dict values are correctly inherited into jinja2 templates, however I appear to have found some corner case or known limitation. I’ve been skimming both the Ansible & Jinja2 docs and have yet to find a working solution - my guess is incompatible YAML syntax. Assuming the following host\_vars:

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [June 29, 2014, 9:04pm UTC](https://forum.ansible.com/t/variable-inheritance-as-dict-within-template/15574/2 "2014-06-29T21:04:54Z")

</div>

Jinja2 is a templating system and Ansible has a variable system that allows Jinja2 evaluation of recursive value references, but we don’t run it wholesale across the file, it’s run on the keys.

Thus, you cannot have the name of a key in a dictionary in Ansible that is a variable, for instance.

(If this differed in value between different hosts, it wouldn’t make any sense to the system, among other things)

---

<div class="post-metadata">

**Author:** ![Matt\_Peterson](https://avatars.discourse-cdn.com/v4/letter/m/3e96dc/32.png) [@Matt\_Peterson](https://forum.ansible.com/u/Matt_Peterson)\
**Post date:** [June 29, 2014, 10:20pm UTC](https://forum.ansible.com/t/variable-inheritance-as-dict-within-template/15574/3 "2014-06-29T22:20:18Z")

</div>

Right, I understand what Jinga2 is… Do you have an alternative approach? Thanks.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [June 30, 2014, 1:56pm UTC](https://forum.ansible.com/t/variable-inheritance-as-dict-within-template/15574/4 "2014-06-30T13:56:23Z")

</div>

I don’t have a solution for what you are trying to do with variable named keys, but let’s step back and try to understand the use case you are trying to model and we can recommend a way to do that.

Can you talk about what you are deploying and configuring and why you think you may need the above idea?
