# Ansible Jinja Templating For issue - Help :)

**URL:** <https://forum.ansible.com/t/ansible-jinja-templating-for-issue-help/24553>\
**Category:** Ansible Project\
**Created:** [May 23, 2017, 6:30pm UTC](https://forum.ansible.com/t/ansible-jinja-templating-for-issue-help/24553 "2017-05-23T18:30:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Owen\_Corcoran](https://avatars.discourse-cdn.com/v4/letter/o/977dab/32.png) [@Owen\_Corcoran](https://forum.ansible.com/u/Owen_Corcoran)\
**Post date:** [May 23, 2017, 6:30pm UTC](https://forum.ansible.com/t/ansible-jinja-templating-for-issue-help/24553/1 "2017-05-23T18:30:41Z")

</div>

Hi Guys,

Im trying to get my ansible script to use the below for loop to populate a configfile template generated from Jinja2.

The line i cant get working is

{% for hostname in {{ redishosts }} %}  
server “{{ hostname }}” {{ hostvars[host][‘ansible\_eth0’][‘ipv4’][‘address’] }} check port 6379 inter 1s\r\n  
{% endfor %}

Im trying to get the hostname the ip4 address and the text around it. Everytime it runs it fails stating expecting : not }

Ive tried everything i can think of but i cant get it working. Any help apreciated

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [May 23, 2017, 6:42pm UTC](https://forum.ansible.com/t/ansible-jinja-templating-for-issue-help/24553/2 "2017-05-23T18:42:57Z")

</div>

> Hi Guys,
> 
> Im trying to get my ansible script to use the below for loop to populate a  
> configfile template generated from Jinja2.
> 
> The line i cant get working is
> 
> {% for hostname in {{ redishosts }} %}

You can't use {{ and }} in between {% %}, so just remove them.

> server "{{ hostname }}" {{  
> hostvars[host]['ansible\_eth0']['ipv4']['address'] }} check port 6379 inter

I guess it's hostname and not host.

---

<div class="post-metadata">

**Author:** ![Owen\_Corcoran](https://avatars.discourse-cdn.com/v4/letter/o/977dab/32.png) [@Owen\_Corcoran](https://forum.ansible.com/u/Owen_Corcoran)\
**Post date:** [May 23, 2017, 10:09pm UTC](https://forum.ansible.com/t/ansible-jinja-templating-for-issue-help/24553/3 "2017-05-23T22:09:30Z")

</div>

Thanks that fixed it . Can you tell me why you can't use them . Just so I know for future reference.

Thanks

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [May 25, 2017, 7:45pm UTC](https://forum.ansible.com/t/ansible-jinja-templating-for-issue-help/24553/4 "2017-05-25T19:45:23Z")

</div>

When you are inside {% %} block, you are in Jinja mode, and in Jinja variables is used only by it's name.

When you are outside of {% %} you need {{ }} to say that this is a Jinja expression.

For more information about Jinja the documentation is here  
[http://jinja.pocoo.org/docs/dev/templates/](http://jinja.pocoo.org/docs/dev/templates/)
