AnsibleError: ошибка шаблона при шаблонной строке: ожидаемый токен «конец блока операторов», получено «{» - PullRequest
0 голосов
/ 31 марта 2019

Получение 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

1 Ответ

1 голос
/ 31 марта 2019

Это линия, которая доставляет вам неприятности: {% for int in int_details_{{item.hostname}} %}.Вы не можете использовать расширение переменной jinja2 внутри инструкции jinja2.

Это решит вашу текущую проблему: {% for int in lookup('vars', 'int_details_' + item.hostname) %}

...