如何解决结束块忽略盐中的忍者模板
我收到了以下无法正常工作的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 %}
当我在小兵的盐中运行此代码时,我得到了:
本地:
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代码的方法。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。