# Loop issue with nested variable and dict

**URL:** <https://forum.ansible.com/t/loop-issue-with-nested-variable-and-dict/18951>\
**Category:** Ansible Project\
**Created:** [August 5, 2015, 10:55am UTC](https://forum.ansible.com/t/loop-issue-with-nested-variable-and-dict/18951 "2015-08-05T10:55:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![R\_Dikkes](https://avatars.discourse-cdn.com/v4/letter/r/7ba0ec/32.png) [@R\_Dikkes](https://forum.ansible.com/u/R_Dikkes)\
**Post date:** [August 5, 2015, 10:55am UTC](https://forum.ansible.com/t/loop-issue-with-nested-variable-and-dict/18951/1 "2015-08-05T10:55:08Z")

</div>

Hi,

I am trying to do the following:

Consul-template needs to generate a haproxy config, the consul template i want to be dynamic filled with Ansible.  
The consul template however is a Go template and unfortunately Go uses the brackets yaml uses. To be able to build a Go template ansible templates i am putting the Go syntax in a variable.

My whole idea is to place all applications that i want consul to generate templates for in a variable file, and let these variables be used in a template i generate to generate the Go template for consul.

I got most of it to work, except for the fact that the variable is looping over the template instead of within the template. I suspect i need to do it all different.

The task file main.yml:

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [August 5, 2015, 1:01pm UTC](https://forum.ansible.com/t/loop-issue-with-nested-variable-and-dict/18951/2 "2015-08-05T13:01:37Z")

</div>

I hit the exact same problem, and someone on IRC pointed me at {% raw  
%}....{% endraw %}

[http://jinja.pocoo.org/docs/dev/templates/#escaping](http://jinja.pocoo.org/docs/dev/templates/#escaping)

---

<div class="post-metadata">

**Author:** ![R\_Dikkes](https://avatars.discourse-cdn.com/v4/letter/r/7ba0ec/32.png) [@R\_Dikkes](https://forum.ansible.com/u/R_Dikkes)\
**Post date:** [August 5, 2015, 1:08pm UTC](https://forum.ansible.com/t/loop-issue-with-nested-variable-and-dict/18951/3 "2015-08-05T13:08:10Z")

</div>

But that would leave alone my Go template language right? It wouldn’t solve the looping over instead of inside the template, am i correct?  
Thank you for your answer! 🙂

---

<div class="post-metadata">

**Author:** ![R\_Dikkes](https://avatars.discourse-cdn.com/v4/letter/r/7ba0ec/32.png) [@R\_Dikkes](https://forum.ansible.com/u/R_Dikkes)\
**Post date:** [August 5, 2015, 11:01pm UTC](https://forum.ansible.com/t/loop-issue-with-nested-variable-and-dict/18951/4 "2015-08-05T23:01:34Z")

</div>

Issue solved. 🙂
