AnsibleError:模板字符串时模板错误:预期标记“语句块结束",得到“{" [英] AnsibleError: template error while templating string: expected token 'end of statement block', got '{'

查看:40
本文介绍了AnsibleError:模板字符串时模板错误:预期标记“语句块结束",得到“{"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Getting AnsibleError: 模板化字符串时出现模板错误:预期标记语句块结束",得到{"

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

这是我的 jinja2 模板,有人可以帮我找出问题所在吗?

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

推荐答案

这是给您带来麻烦的行:{% for int in int_details_{{item.hostname}} %}.您不能在 jinja2 指令中使用 jinja2 变量扩展.

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.

这将解决您当前的问题:{% for int in lookup('vars', 'int_details_' + item.hostname) %}

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

这篇关于AnsibleError:模板字符串时模板错误:预期标记“语句块结束",得到“{"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆