You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SaltStack SLS文件Jinja语法错误求助:未知'endblock'标签

Fixing Jinja Syntax Error & Other Issues in Your SLS Code

Let's break down and fix the problems in your SLS configuration step by step:

1. Root Cause of the Jinja Syntax Error

The immediate error is the unnecessary {% endblock %} tag at the end of your code. Jinja throws this error because there's no corresponding {% block %} tag defined anywhere in your SLS—this tag only applies when extending Jinja templates, which you're not doing here. Simply delete this line entirely.

2. Fix pillar.get Variable Interpolation

You're using Jinja double curly braces {{ }} inside the string passed to salt['pillar.get'], which won't work because the single quotes make the content a literal string (Jinja won't parse variables inside it). Instead, use Jinja's string concatenation operator ~ to build the pillar path:

{% 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') %} 

3. Correct the Loop Iteration

Your loop line {% for user, args in ['userConfigList'].items() %} is invalid:

  • ['userConfigList'] is a list containing a single string, not the variable you defined earlier
  • Lists don't have an items() method (that's for dictionaries)

Replace it with a loop over your actual userConfigList variable:

{% for user, args in userConfigList.items() %}

4. Remove Redundant Commented Code

The line #{% for user, args in pillar['users'].items() %} is commented out and serves no purpose—delete it to clean up your code.

Full Corrected SLS Code

{% 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 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 %}

Additional Notes

  • Ensure your pillar data for create-login-users_Linux:p_userData:userConfigList is structured as a dictionary where each key is a username, and the value is a dict containing the user attributes (gid, home, etc.)
  • Test the rendered SLS first with salt <minion-id> slsutil.renderer salt://path/to/your/file.sls to catch any remaining Jinja issues before applying it.

内容的提问来源于stack exchange,提问作者Arch

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 06:22:27