我得到了下面的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 %}当我从奴才那里用salt运行这段代码时,我得到:
当地:
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 %}{%结束%}
{%结束块%} <======================
我想能解决这个问题,请帮帮忙。
发布于 2020-09-21 10:23:30
您的问题很可能是,为了“注释”第一个for循环,您使用了一个#。
但这并没有达到您预期的效果:您的for循环仍然存在。
因此,您有两个for循环,而只有一个and for。这不对。
要解决您的问题,需要使用Jinja注释:
{# for user, args in pillar['users'].items() #}
{% for user, args in ['userConfigList'].items() %}{# .... #}是注释jinja代码的方法。
https://stackoverflow.com/questions/63814622
复制相似问题