Salt State结合Pillar数据运行失败,报错状态未按列表定义求助
Fixing the Salt State Compilation Error
Let's break down the issue and fix your Salt State file step by step.
The Root Cause
The error message mentions the radiusgroup state isn't formed as a list, but the actual culprit is a syntax mistake in your first state (freeradius). In Salt, when defining a state with no arguments, you need to explicitly indicate it's a state function (not just a string) by adding a colon and an empty list. Your original freeradius line was missing this, which confused the YAML parser and led to a misleading error about the radiusgroup state.
Corrected Salt State
Here's the fixed version of your SLS file:
freeradius: pkg.installed: [] # Added colon and empty list for valid state syntax radiusgroup: group.present: - name: radiusadm - gid: 666 {% for user, args in pillar['users'].items() %} {% if ( user not in pillar['absents'] ) and ( 'radiuspassword' in args ) %} shadow_hash_{{ user }}: user.present: - name: {{ user }} - password: {{ args['radiuspassword'] }} {% endif %} {% endfor %}
Key Changes Explained
- Fixed
freeradiusstate: Changedpkg.installedtopkg.installed: []. This tells Salt thatpkg.installedis a state function with no arguments, which aligns with Salt's required YAML structure. - Preserved valid
radiusgroupstate: Your originalgroup.presentconfiguration was already correct (using a list of arguments), so no changes were needed here. - Jinja templating remains intact: The loop for user accounts is correctly structured and will work as expected once the YAML syntax is fixed.
Additional Checks
- Ensure all indentation uses spaces (not tabs) — YAML is strict about this, and tabs can cause hidden parsing errors.
- Your Pillar data is correctly formatted, so no changes are needed there.
Content of the question来源于stack exchange,提问作者sapios
相关产品推荐
相关产品推荐

