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

26,662

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) %}

Share:
26,662

Related videos on Youtube

Prarthana Shedge
Author by

Prarthana Shedge

Updated on March 31, 2020

Comments

  • Prarthana Shedge
    Prarthana Shedge about 4 years

    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