@(学习)[SaltStack]
SaltStack实战之远程执行-Targeting minion id配置Targeting分类SaltStack远程执行组成部分: * 目标(Targeting) * 模块(Module) * 返回(Returnners)
minion id可以定义在minion配置文件中,如果未定义,默认使用的是hostname。minion id是不能变动的,因为minion与master认证公钥是以minion id命名文件名的。 [root@salt-master111 pillar]# vim /etc/salt/minion
id: salt-master111Minion id命名越规范越详细,在使用minion id匹配过程中就越准确。
和Minion ID有关,需要使用Minion ID: * Globbing(通配符) * regex(正则表达式) * List(列表)
通配符匹配
[root@salt-master111 pillar]# salt "10.1.0.*" test.ping 10.1.0.112: True 10.1.0.95: True 10.1.0.50: True 10.1.0.96: True [root@salt-master111 pillar]# salt "10.1.0.[!1]*" test.ping 10.1.0.95: True 10.1.0.50: True 10.1.0.96: True正则匹配
[root@salt-master111 pillar]# salt -E "10.1.0.(95|96)" test.ping 10.1.0.95: True 10.1.0.96: True列表匹配
[root@salt-master111 pillar]# salt -L "10.1.0.95,10.1.0.96" test.ping 10.1.0.95: True 10.1.0.96: True和Minion ID无关,不涉及到Minion ID: * 子网/IP地址 * Grains * Pillar * Compound matchers(复合匹配) * Node groups(节点组) * Batching execution(批处理执行)
IP地址匹配
[root@salt-master111 pillar]# salt -S "10.1.0.50" test.ping 10.1.0.50: TrueGrains匹配
[root@salt-master111 pillar]# salt -G "os:CentOS" test.ping 10.1.0.95: True 10.1.0.112: True 10.1.0.50: True salt-master111: True 10.1.0.96: TruePillar匹配
[root@salt-master111 salt]# salt -I "Zabbix_Server:10.1.0.111" test.ping 10.1.0.112: True复合匹配
LetterMatch Type例如:Alt Delimiter?GGrains globG@os:UbuntuYesEPCRE Minion IDE@web\d+\.(dev|qa|prod)\.locNoPGrains PCREP@os:(RedHat|Fedora|CentOS)YesLList of minionsL@minion1.example.com,minion3.domain.com or bl*.domain.comNoIPillar globI@pdata:foobarYesJPillar PCREJ@pdata:^(foo|bar)$YesSSubnet/IP addressS@192.168.1.0/24 or S@192.168.1.100NoRRange clusterR@%foo.barNoMatchers can be joined using boolean and, or, and not operators.
[root@salt-master111 salt]# salt -C "G@os:CentOS and S@10.1.0.112" test.ping 10.1.0.112: True [root@salt-master111 salt]#Nodgroups
nodegroups master配置文件参数用于定义节点组。这里有一个通过/etc/salt/master配置文件配置节点组的例子:
#nodegroups: # group1: 'L@foo.domain.com,bar.domain.com,baz.domain.com or bl*.domain.com' # group2: 'G@os:Debian and foo.domain.com' # group3: 'G@os:Debian and N@group1' # group4: # - 'G@foo:bar' # - 'or' # - 'G@foo:baz' nodegroups: test112: '10.1.0.112' [root@salt-master111 ~]# salt -N 'test112' test.ping 10.1.0.112: True [root@salt-master111 ~]#批处理执行
[root@salt-master111 salt]# salt '*' -b 2 test.ping在top.sls中,使用正则和grains匹配写法:
"10.1.0.(95|96)": - match: pcre - apache "os:CentOS": - match: grain - apache其它targeting详情:http://docs.saltstack.cn/topics/targeting/index.html
