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:
---
uniq_id: 255
vlans: {
2: {
description: "working VLAN 2 on unique host {{ uniq_id }}",
},
5: {
description: "another example",
},
"{{ uniq_id }}": {
description: "not working",
}
}
Using the following template:
Working dict {{ uniq_id }} value
{% for vlan in vlans|dictsort %}
Matched VLAN id {{ vlan[0]|string }} for {{ vlan[1].description }}
{% endfor %}
The result is:
Working dict 255 value
Matched VLAN id 2 working VLAN 2 on unique host 255
Matched VLAN id 4 for another example
Matched VLAN id {{ uniq_id }} for not working
The environment is ansible (1.6.3) & jinga2 (2.7.3), again it looks like substitution works fine for strings and values, but not array keys? Much appreciate any guidance on what could be happening here, thank you.
--Matt