如何获得所需的输出?
yaml
nodeStatusUpdateFrequency:
{% if nodeStatusUpdateFrequency is defined -%}
{{ nodeStatusUpdateFrequency }}
{% else -%}
{%- if nodeStatusUpdate == 'Fast' -%}
4s
{%- elif nodeStatusUpdate == 'Medium' -%}
20s
{%- elif nodeStatusUpdate == 'Low' -%}
1m
{% else -%}
10s
{% endif %}
{%- endif %}
oomScoreAdj: -999
我当前的输出是:
nodeStatusUpdateFrequency: $x
oomScoreAdj: -999
我的预期输出是:
nodeStatusUpdateFrequency: $xoomScoreAdj: -999
答案 0 :(得分:0)
您的模板正常。下面的播放带有模板的复制和粘贴
vars:
nodeStatusUpdateFrequency: "$x"
nodeStatusUpdate: "NONE"
tasks:
- template:
src: test-template.j2
dest: /scratch/test.txt
给予:
# cat /scratch/test.txt
nodeStatusUpdateFrequency: $x
oomScoreAdj: -999
答案 1 :(得分:0)
您只是在某些endif控制结构上缺少减号(-)。这正在按照您的期望进行:
nodeStatusUpdateFrequency:
{%- if nodeStatusUpdateFrequency is defined -%}
{{ nodeStatusUpdateFrequency }}
{%- else -%}
{%- if nodeStatusUpdate == 'Fast' -%}
4s
{%- elif nodeStatusUpdate == 'Medium' -%}
20s
{%- elif nodeStatusUpdate == 'Low' -%}
1m
{%- else -%}
10s
{%- endif -%}
{%- endif -%}
oomScoreAdj: -999