Prarthana Shedge
Prarthana Shedge

Reputation: 155

AnsibleError: template error while templating string: expected token 'end of statement block', got '{'

Getting AnsibleError: template error while templating string: expected token 'end of statement block', got '{'

Here is my jinja2 template, can someone help me figure out what is wrong?

no service pad
service tcp-keepalives-in
service tcp-keepalives-out
service timestamps debug datetime msec localtime show-timezone
service timestamps log datetime msec localtime show-timezone
service password-encryption
!
hostname {{item.hostname}}
!
boot-start-marker
boot-end-marker
!
logging buffered 32000
no logging console
!
!
{% for int in int_details_{{item.hostname}} %}
interface {{int.int}}
 ip address {{int.ip}} {{int.mask}}
 no shutdown
 !
!
{% endfor %}
!
{% if (item.OSPF == 'Yes') and (item.hostname == 'R1') %}
router ospf {{item.OSPF_id}}
 network 0.0.0.0 0.0.0.0 area {{item.OSPF_area}}
{% elif (item.OSPF == 'Yes') and (item.hostname == 'R2') %}
router ospf {{item.OSPF_id}}
 network 0.0.0.0 0.0.0.0 area {{item.OSPF_area}}
{% elif (item.OSPF == 'Yes') and (item.hostname == 'R3') %}
router ospf {{item.OSPF_id}}
 network 0.0.0.0 0.0.0.0 area {{item.OSPF_area}}
{% endif %}
end

Upvotes: 2

Views: 33120

Answers (1)

Zeitounator
Zeitounator

Reputation: 44635

This is the line that's causing you trouble: {% for int in int_details_{{item.hostname}} %}. You cannot use jinja2 variable expansion inside a jinja2 instruction.

This will solve your current problem: {% for int in lookup('vars', 'int_details_' + item.hostname) %}

Upvotes: 4

Related Questions