minion id 是 minion 公/私钥对的名字,如果修改了 minion id ,master 需要重新接受新的key,
否则 minion 不能通过 master 的认证。操作和添加新的 minion 一样。
shell通配符Globbing
Salt默认使用shell风格通配符('*','?','[]')来匹配minion>。在State系统中的top file也一样。
Note:
使用 salt 命令时必须将'*'放在单引号中,或是用'\'转义,不然 shell 会在 salt 之前扩展'*'。
匹配所有客户端:
salt '*' test.ping 匹配所有example.net域或者example域的客户端:
salt '*.example.net' test.ping
salt '*.example.*' test.ping
匹配example.net域中的webN客户端(web1.example.net, web2.example.net … webN.example.net):
salt 'web?.example.net' test.ping 匹配web1到web5:
salt 'web[1-5]' test.ping 匹配web1和web3
salt 'web[1,3]' test.ping 匹配web-x,web-y,web-z:
salt 'web-[x-z]' test.ping
正则表达式 Regular Expressions
Salt可以使用Perl风格的正则表达式来匹配minion>,使用选项-E
匹配web1-prod和web1-devel:
salt -E 'web1-(prod|devel)' test.ping 在State的top file,需要将匹配方式作为第一个选项。以下例子在和上面相同的客户端上执行webserver中的内容
base:
'web1-(prod|devel)':
- match: pcre
- webserver
minion列表 Lists
最基本的,可以列出每一个minion>来指定多个目标机器,使用选项'-L'。
[root@localhost ~]# salt -L 'salt_minion_001,salt_minion_002' test.ping
salt_minion_001:
匹配所有系统是CentOS的客户端:
salt -G 'os:CentOS' test.ping 匹配所有64位CPU的机器,并返回CPU核心数:
salt -G 'cpuarch:x86_64' grains.item num_cpus grains.item列出所有grains的名字及内容。
salt '*' grains.items有哪些可用的grains?
grains在客户端上运行,收集客户端的信息,所有不同的客户端可以有不同的grains。使用grains.ls模块列出目标机器上所有可用的grains的名字。
salt '*' grains.ls grains.item列出所有grains的名字及内容。
salt '*' grains.items
nodegroups配置示例:
nodegroups:
group1: 'L@foo.domain.com,bar.domain.com,baz.domain.com or bl*.domain.com'
group2: 'G@os:Debian and foo.domain.com
使用-N选项:
salt -N group1 test.ping 在top file中用 - match: nodegroup来指定使用节点组匹配。
base:
group1:
- match: nodegroup
- webserver 复合匹配 Compound matchers
Compound matcher
用布尔操作符连接的多个目标条件。
复合匹配可以用前面讨论的几种方式实现更精确的匹配。复合匹配默认使用Globbing,要使用其他匹配方式的话,需要加上类型前缀字母,现在实现的字母详细列表,请参考文档。
LetterMatch Type 例如:
GGrains globG@os:UbuntuEPCRE Minion>复合匹配中也可以使用and,or,not操作符,比如说,下面的命令匹配主机名以webserv开始且运行Debian系统的minion,还匹配主机名满足正则web-dc1-srv.*的minion。
salt -C 'webserv* and G@os:Debian or E@web-dc1-srv.*' test.ping 本例中,G表示用shell通配符匹配grains;E表示用正则匹配minion>。
这个例子在top file中如下
base:
'webserv* and G@os:Debian or E@web-dc1-srv.*':
- match: compound
- webserver
注意not不能用于第一个条件,需要用如下命令:
salt -C '* and not G@kernel:Darwin' test.ping批量执行 Batch>