使用 pillar 中定义的角色定位 minions
Target minions using roles defined in pillar
在 /srv/salt/pillar/servers.sls
中有这个结构
servers:
# Monitors
- m1:
- roles: [ monitor ]
- ips: [ 192.168.0.1 ]
- b2:
- roles: [ monitor ]
- ips: [ 192.168.0.2 ]
# BPs
- w2:
- roles:
- webserver:
- type: [ apache ]
- ips: [ 192.168.0.3 ]
我想在我的 top.sls 文件中使用该信息。
我如何 select 例如具有监控角色的服务器?或者类型为 apache 的服务器?
base:
'*':
- common
{% Filter the servers that have the rol monitor %}
- mon
{% endfor %}
{% Filter the servers that have the type apache %}
- web_apache
{% endfor %}
根据 the documentation,这个有效:
# Any minion for which the pillar key 'somekey' is set and has a value
# of that key matching 'abc' will have the 'xyz.sls' state applied.
'somekey:abc':
- match: pillar
- xyz
...但我认为它不适合您的用例。您的 "roles" 项目是一个列表,我猜您想要更像 "if any item in that list is "monitor" 的东西,应用状态 X。这样不行。
我很确定你的方法有缺陷。不要使用支柱文件将服务器映射到角色并从那里映射到状态,只需直接在顶部执行即可:
base:
'*':
- common
'm*':
- mon
'w*':
- web_apache
毕竟这是 top 的预期目的。如果您的 minion ID 不适合 glob,请查看节点组作为替代方案。
在 /srv/salt/pillar/servers.sls
中有这个结构servers:
# Monitors
- m1:
- roles: [ monitor ]
- ips: [ 192.168.0.1 ]
- b2:
- roles: [ monitor ]
- ips: [ 192.168.0.2 ]
# BPs
- w2:
- roles:
- webserver:
- type: [ apache ]
- ips: [ 192.168.0.3 ]
我想在我的 top.sls 文件中使用该信息。
我如何 select 例如具有监控角色的服务器?或者类型为 apache 的服务器?
base:
'*':
- common
{% Filter the servers that have the rol monitor %}
- mon
{% endfor %}
{% Filter the servers that have the type apache %}
- web_apache
{% endfor %}
根据 the documentation,这个有效:
# Any minion for which the pillar key 'somekey' is set and has a value
# of that key matching 'abc' will have the 'xyz.sls' state applied.
'somekey:abc':
- match: pillar
- xyz
...但我认为它不适合您的用例。您的 "roles" 项目是一个列表,我猜您想要更像 "if any item in that list is "monitor" 的东西,应用状态 X。这样不行。
我很确定你的方法有缺陷。不要使用支柱文件将服务器映射到角色并从那里映射到状态,只需直接在顶部执行即可:
base:
'*':
- common
'm*':
- mon
'w*':
- web_apache
毕竟这是 top 的预期目的。如果您的 minion ID 不适合 glob,请查看节点组作为替代方案。