如何在状态 sls 文件中评论 jinja 代码(# 不工作)

how to comment jinja code in a state sls file (# not working)

我无法在状态文件中注释掉神社代码, 我在 sls 文件中有一个 for 循环

{% for user_name in salt['pillar.get']('userlist') %}

get_user:
    - Some code here
    ....

{% endfor %}

我正在用 # 注释掉它,但是当我在 minion 中执行状态时循环仍然 运行。

# {% for user_name in salt['pillar.get']('userlist') %}

get_user:
    - Some code here
    ....

# {% endfor %}

我错过了什么?

将它们放在 {# ... #} 中:

{# {% for user_name in salt['pillar.get']('userlist') %} #}

get_user:
    - Some code here
    ....

{# {% endfor %} #}

您正在使用 YAML 注释 (#) 注释 jinja 代码,而您的 for 循环仍然是 运行 的原因是 by default SLS files are rendered as Jinja templates先,然后解析为YAML文档。

您需要使用 jinja 评论,{# ..... #}

{# {% for user_name in salt['pillar.get']('userlist') %} #}

get_user:
    - Some code here
    ....

{# {% endfor %} #}