【发布时间】:2021-04-16 08:29:49
【问题描述】:
我已经创建了 jinja2 模板来使用以下代码生成我的 json 文件。 我的变量如下:
network_profile:
- Internal
- Custom
如果我使用了以上 2 个变量,那么我不会得到如下所述的输出。第二个循环的 v_value 变为自定义。我希望它是内部的
如果我使用 3 个变量,那么它可以正常工作并根据我的要求低于输出。知道我想念的地方
{
"p_data": [
{
"u_label": "Internal",
"u_catalog_item": "abc",
"u_value": "Internal"
},
{
"u_label": "Custom",
"u_catalog_item": "abc",
"u_value": "Internal"
}
]
}
{
"p_data": [
{% for network in network_profile %}
{% if loop.index == loop.length %}
{
"u_label": "{{ network }}",
"u_catalog_item": "{{ catalog_item }}",
"u_value": "{{ network }}"
}
{% else %}
{
"u_label": "{{ network }}",
"u_catalog_item": "{{ catalog_item }}",
"u_value": "Internal"
},
{% endif %}
{% endfor %}
]
}
【问题讨论】:
标签: ansible-template