如何解决盐状态无法与支柱数据结合使用
我有以下盐状态:
freeradius:
pkg.installed
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 %}
并具有以下支柱
groups:
radiusd:
gid: 95
users:
user1:
radiuspassword: 'password1'
user2:
radiuspassword: 'password2'
absents:
a2user1:
a2user2:
我想使此代码正常工作,我收到消息:
Data failed to compile:
State 'radiusgroup' in SLS 'radiusd' is not formed as a list
请告诉我如何从这里出发,谢谢。
解决方法
我认为问题出在pillar
的声明中。在状态文件for
和if
中也有缩进可能会导致问题。错误指出radiusgroup
未形成为列表。因此,我们应该与groups
组成一个列表。
支柱示例:
groups:
- name: radiusd
gid: 95
users:
- name: user1
radiuspassword: password1
- name: user2
radiuspassword: password2
absents:
- a2user1
- a2user2
请注意,我对用户列表也使用了类似的结构。然后我们可以将状态文件设置为:
{% for group in pillar['groups'] %}
radiusgroup_{{ group.name }}:
group.present:
- name: {{ group.name }}
- gid: {{ group.gid }}
{% endfor %}
{% for user in pillar['users'] %}
{% if (user.radiuspassword is defined) and (user.name not in pillar['absents']) %}
shadow_hash_{{ user.name }}:
user.present:
- name: {{ user.name }}
- password: {{ user.radiuspassword }}
{% endif %}
{% endfor %}
如果pillar
在您的控制范围内,则最好精确地定义它。这样就可以避免在状态文件中使用复杂的Jinja表达式。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。