【发布时间】:2020-03-11 19:51:07
【问题描述】:
尝试使用 Jinja2 在 ansible 中设置一个事实。
得到以下错误
错误:模板化字符串时出现模板错误:预期的标记',',得到':'
PFB代码
- set_fact:
lb_lstnr_map: []
- name: "Build listeners map"
set_fact:
lb_lstnr_map: >-
{%- if item == 443 and cert_arn -%}
{{ lb_lstrn_map.extend({
'Protocol': 'HTTPS',
'Port': 443,
'DefaultActions': [ { 'Type': 'forward', 'TargetGroupName': tg_name } ],
'SslPolicy': ssl_policy,
'Certificates': [ { 'CertificateArn': cert_arn } ] })
}}
{%- else -%}
{{ lb_lstrn_map.extend({
'Protocol': 'TCP' if lb_type = 'network' else 'HTTP',
'Port': item,
'DefaultActions': [ {'Type': 'forward', 'TargetGroupName': tg_name } ]
}
})
}}
{% endif %}
with_items: lb_listeners
【问题讨论】: