saltstack(四) saltstack的targeting、分组

targeting支持如下matcher:

Globing :   '*',
正则:      指定-E参数,正则表达式匹配多个
List:      指定-L参数,salt -E 'web1-(prod|devel)' test.ping 
Grains:    指定-G参数,salt -G 'os:CentOS' test.ping
pillar:    指定-I参数,salt -I 'apache:httpd' pkg.install httpd
node groups: 指定-N参数,salt -N 'web-cluster' test.ping
base:
web-cluster:
- match:nodegroup
- webserver
混搭(compound)
batch size
     Letter Match Type Example
         G Grans glob G@os:Ubuntu
         E PCRE Minion
ID
E@webd+.(dev|qa|prod).loc
         P Grains PCRE P@os:(RedHat|Fedora|CentOS)
         L List of minions L@minion1.example.com,minion3.domain.com or
bl
*
.domain.com
         I Pillar glob I@pdata:foobar
         S Subnet/IP
address
S@192.168.1.0/24 or S@192.168.1.100
         R Range cluster R@%foo.bar

上图是targeting的其中方式,具体用法不在一一实验.

下面介绍一下saltstack的分组:

 为了便于管理功能业务相似的minion,Saltstack提供了分组的模式,Node group为预先在master配置文件中定义的minion组.用来进行批量对minion进行操作.

  编辑配置文件 vi /etc/salt/master

 ##### Node Groups #####

##########################################

# Node groups allow for logical groupings of minion nodes.

# A group consists of a group name and a compound target.

#

#nodegroups:

# group1: ‘L@foo.domain.com,bar.domain.com,baz.domain.com and bl*.domain.com’

# group2: ‘G@os:Debian and foo.domain.com’

具体配置如下:

nodegroups:
 group1: 'L@test1.sina.com,test2.sina.com'
 group2: '192.168.10.15'

重启master生效

salt -N testgroup1 test.ping   ##使用-N 匹配刚刚定义的主机组

下面附上nodegroup的高级用法:

  关于组的混合匹配:(Compound matchers)

 为了是master文件更加整洁,可以将分组的文件放到/etc/salt/master.d/下面,会自动加载

原文地址:https://www.cnblogs.com/phennry/p/5416408.html