在使用 SaltStack 对主机进行批量管理的时候,因为不同的服务器组所做的业务功能不同,因此为了更加方便的管理,势必要对主机进行分组管理。

 

  1. G -- 针对 Grains 做单个匹配,例如:G@os:Ubuntu
  2. E -- 针对 minion 针对正则表达式做匹配,例如:E@web\d+.(dev|qa|prod).loc
  3. P -- 针对 Grains 做正则表达式匹配,例如:P@os:(RedHat|Fedora|CentOS)
  4. L -- 针对 minion 做列表匹配,例如:L@minion1.example.com,minion3.domain.com or bl*.domain.com
  5. I -- 针对 Pillar 做单个匹配,例如:I@pdata:foobar
  6. S -- 针对子网或是 IP 做匹配,例如:S@192.168.1.0/24 or S@192.168.1.100
  7. R -- 针对客户端范围做匹配,例如: R@%foo.bar

 

#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:

            testgroup1: 'E@192.168.8.11[6-7]'
            testgroup2: 'L@192.168.8.116,192.168.8.117'
            testgroup3: 'G@os:Centos'
            testgroup4: 'S@192.168.8.0/24'

[root@redis_server ~]# salt -N testgroup1 'test.ping'
192.168.8.117:
True
192.168.8.116:
True

 

[root@redis_server ~]# salt -N testgroup2 'test.ping'
192.168.8.117:
True
192.168.8.116:
True

 

[root@redis_server ~]# salt -N testgroup3 'test.ping'
192.168.8.117:
True

 

[root@redis_server ~]# salt -N testgroup4 'test.ping'
192.168.8.117:
True
192.168.8.116:
True

结论

使用 L 列表的方式,必须把 minion 列出来,或者是列出几台后,在后面接 or 或者 and 表达式, or 或者 and 后面接的表达式后面可以使用正则表达式。

注:想使用正则表达式,最好的方式就是使用 E

posted on 2017-06-09 15:18  绿旋风-1  阅读(143)  评论(0编辑  收藏  举报