【问题标题】:AnsibleError: template error while templating string: expected token 'end of statement block', got '{'AnsibleError:模板化字符串时出现模板错误:预期标记“语句块结束”,得到“{”
【发布时间】:2019-03-31 03:13:38
【问题描述】:

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

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

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

【问题讨论】:

    标签: ansible jinja2


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-06
      • 2022-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-07
      相关资源
      最近更新 更多