在/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文件中使用该信息。
例如,如何选择具有监视角色的服务器?还是类型为apache的服务器?
base:
'*':
- common
{% Filter the servers that have the rol monitor %}
- mon
{% endfor %}
{% Filter the servers that have the type apache %}
- web_apache
{% endfor %}
答案 0 :(得分:0)
根据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
...但是我认为它不适合您的用例。您的“角色”项是一个列表,我猜您想要更多类似“如果该列表中的任何项是“监视器”,则应用状态X。这种方式行不通。
我很确定您的方法存在缺陷。不用直接使用支柱文件将服务器映射到角色以及从服务器映射到状态,只需直接在顶部进行操作即可:
base:
'*':
- common
'm*':
- mon
'w*':
- web_apache
毕竟,这是最高目的。如果您的爪牙ID不太适合全局,请另选节点组。