Search code examples
salt-project

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


i am having trouble commenting out jinja code in a state file, i have a for loop in sls file

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

get_user:
    - Some code here
    ....

{% endfor %}

i am commenting it out with #, but the loop still running when i execute state in a minion.

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

get_user:
    - Some code here
    ....

# {% endfor %}

what i am missing?


Solution

  • You are commenting jinja code using YAML comment (#), and the reason your for loop is still running is because by default SLS files are rendered as Jinja templates first, and then parsed as YAML documents.

    You need to use jinja comment instead, {# ..... #}

    {# {% for user_name in salt['pillar.get']('userlist') %} #}
    
    get_user:
        - Some code here
        ....
    
    {# {% endfor %} #}