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

丶灬走出姿态 提交于 2019-12-24 00:42:54

问题


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

回答1:


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



来源:https://stackoverflow.com/questions/55437561/ansibleerror-template-error-while-templating-string-expected-token-end-of-sta

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!