块结束忽略忍者在盐中的模板
end for block ignored ninja templating in salt
我得到以下无效的 sls 代码
{% set pillarTree = 'create-login-users_Linux' %}
{% set saltFileSystem = salt['pillar.get']('{{ pillarTree }}:p_metaData:saltFileSystem') %}
{% set userConfigList = salt['pillar.get']('{{ pillarTree }}:p_userData:userConfigList') %}
{% set sftpGroupId = salt['pillar.get']('{{ pillarTree }}:p_userData:loginGroupId') %}
{% if ( grains ['kernel'] == 'Linux' ) %}
#{% for user, args in pillar['users'].items() %}
{% for user, args in ['userConfigList'].items() %}
{{ user }}:
group.present:
- gid: {{ args['gid'] }}
user.present:
- home: {{ args['home'] }}
- shell: {{ args['shell'] }}
- uid: {{ args['uid'] }}
- gid: {{ args['gid'] }}
{% if 'password' in args %}
- password: {{ args['password'] }}
{% if 'enforce_password' in args %}
- enforce_password: {{ args['enforce_password'] }}
{% endif %}
{% endif %}
- fullname: {{ args['fullname'] }}
{% if 'groups' in args %}
- groups: {{ args['groups'] }}
{% endif %}
- require:
- group: {{ user }}
{% if 'key.pub' in args and args['key.pub'] == True %}
{{ user }}_key.pub:
ssh_auth:
- present
- user: {{ user }}
- source: salt://quicken/users/{{ user }}/keys/key.pub
{% endif %}
{% endfor %}
{% endif %}
当我 运行 这个来自 minion 的盐中的代码时,我得到:
本地:
Data failed to compile:
Rendering SLS 'test:quicken.create-login-user_Linux' failed: Jinja syntax error: Encountered unknown tag 'endblock'. You probably made a nesting mistake. Jinja is expecting this tag, but currently looking for 'endfor' or 'else'. The innermost block that needs to be closed is 'for'.; line 39
[...]
- present
- user: {{ user }}
- source: salt://quicken/users/{{ user }}/keys/key.pub
{% endif %}
{% endfor %}
{% endblock %} <======================
我希望能够解决这个问题,请帮忙。
您的问题很可能是为了“评论”第一个 for 循环,您使用了 #.
但这并没有达到您预期的效果:您的 for 循环仍然存在。
因此,您有两个 for 循环,只有一个 endfor。这是不正确的。
要解决您的问题,您需要使用 Jinja 评论:
{# for user, args in pillar['users'].items() #}
{% for user, args in ['userConfigList'].items() %}
{# .... #}
是注释 jinja 代码的方式。
我得到以下无效的 sls 代码
{% set pillarTree = 'create-login-users_Linux' %}
{% set saltFileSystem = salt['pillar.get']('{{ pillarTree }}:p_metaData:saltFileSystem') %}
{% set userConfigList = salt['pillar.get']('{{ pillarTree }}:p_userData:userConfigList') %}
{% set sftpGroupId = salt['pillar.get']('{{ pillarTree }}:p_userData:loginGroupId') %}
{% if ( grains ['kernel'] == 'Linux' ) %}
#{% for user, args in pillar['users'].items() %}
{% for user, args in ['userConfigList'].items() %}
{{ user }}:
group.present:
- gid: {{ args['gid'] }}
user.present:
- home: {{ args['home'] }}
- shell: {{ args['shell'] }}
- uid: {{ args['uid'] }}
- gid: {{ args['gid'] }}
{% if 'password' in args %}
- password: {{ args['password'] }}
{% if 'enforce_password' in args %}
- enforce_password: {{ args['enforce_password'] }}
{% endif %}
{% endif %}
- fullname: {{ args['fullname'] }}
{% if 'groups' in args %}
- groups: {{ args['groups'] }}
{% endif %}
- require:
- group: {{ user }}
{% if 'key.pub' in args and args['key.pub'] == True %}
{{ user }}_key.pub:
ssh_auth:
- present
- user: {{ user }}
- source: salt://quicken/users/{{ user }}/keys/key.pub
{% endif %}
{% endfor %}
{% endif %}
当我 运行 这个来自 minion 的盐中的代码时,我得到:
本地:
Data failed to compile:
Rendering SLS 'test:quicken.create-login-user_Linux' failed: Jinja syntax error: Encountered unknown tag 'endblock'. You probably made a nesting mistake. Jinja is expecting this tag, but currently looking for 'endfor' or 'else'. The innermost block that needs to be closed is 'for'.; line 39
[...]
- present
- user: {{ user }}
- source: salt://quicken/users/{{ user }}/keys/key.pub
{% endif %}
{% endfor %}
{% endblock %} <======================
我希望能够解决这个问题,请帮忙。
您的问题很可能是为了“评论”第一个 for 循环,您使用了 #.
但这并没有达到您预期的效果:您的 for 循环仍然存在。
因此,您有两个 for 循环,只有一个 endfor。这是不正确的。
要解决您的问题,您需要使用 Jinja 评论:
{# for user, args in pillar['users'].items() #}
{% for user, args in ['userConfigList'].items() %}
{# .... #}
是注释 jinja 代码的方式。