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
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.
Thanks that fixed it . Can you tell me why you can't use them . Just so I know for future reference.
Thanks
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/