1、为什么要分组

  使用saltstack可以在很大程度上简化我们的工作,特别是在机器特别多的场景,并且业务较复杂的情况下,因此分组就显得非常重要了。


2、定义分组

root@master salt]# vim /etc/salt/master
nodegroups:
  group01: 'L@node01.saltstack.com,node02.saltstack.com'
  group02: 'S@10.10.10.0/24'
  group03: 'E@node0[1-2].saltstack.com'

3、根据自己定义的分组进行测试

[root@master salt]# /etc/init.d/salt-master restart
Stopping salt-master daemon:                               [确定]
Starting salt-master daemon:                               [确定]
[root@master salt]# salt -N group01 test.ping
node02.saltstack.com:
    True
node01.saltstack.com:
    True
[root@master salt]# salt -N group02 test.ping
node01.saltstack.com:
    True
node02.saltstack.com:
    True
[root@master salt]# salt -N group03 test.ping
node01.saltstack.com:
    True
node02.saltstack.com:
    True
[root@master salt]# salt -N group01 cmd.run 'uptime'
node02.saltstack.com:
     22:34:22 up  4:25,  0 users,  load average: 0.00, 0.00, 0.00
node01.saltstack.com:
     22:34:22 up  4:25,  1 user,  load average: 0.00, 0.00, 0.00

4、关于saltstack分组的补充信息

参数含义举例
G
Grains glob匹配G:os:ubuntu
E
PCRE Minion id匹配 E@web\d+\. (dev|qa|prod)\.loc
PGrains PCRE匹配P@os:(RedHat|Fedora|CentOS)
Lminions列表L@node01.saltstack.com,node02.saltstack.com or openstack*.saltstack.com
IPillar glob匹配I@pdata:foobar
S子网/IP地址匹配S@10.10.10.0/24 or S@10.10.10.140
RRange cluster匹配R@foo.bar
DMinion Data匹配D@key:value