Node groups和Compound matchers(混合匹配)

来源:互联网 发布:mac系统重装教程 u盘 编辑:程序博客网 时间:2024/05/20 02:26

转自:http://wiki.saltstack.cn/topics/targeting/nodegroups

Node groups

Node group为预先在master配置文件中定义的minion组.用来进行批量对minion进行操作.

更多关于批量操作minion的方法可以参考: Compound matchers

Node group配置使用比较简单,直接上例子:

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参数在命令行指定运行的nodegroup:

salt -N group1 test.ping

top.sls中指定nodegroup:

base:  group1:    - match: nodegroup    - webserver


* 原文:http://docs.saltstack.com/topics/targeting/compound.html * 译者:pengyao

混合匹配

混合匹配(Compound matchers)是指在操作时使用多种预定义的匹配方法。默认匹配规则是glob. 在使用混合匹配时,需要先匹配前指定letter, 当前支持的“letter”有:

Letter

含义

例子

G

Grains glob匹配

G@os:Ubuntu

E

PCRE Minion id匹配

E@web\d+\.(dev|qa|prod)\.loc

P

Grains PCRE匹配

P@os:(RedHat|Fedora|CentOS)

L

minions列表

L@minion1.example.com,minion3.domain.com or bl*.domain.com

I

Pillar glob匹配

I@pdata:foobar

S

子网/IP地址匹配

S@192.168.1.0/24 or S@192.168.1.100

R

Range cluster匹配

R@%foo.bar

D

Minion Data匹配

D@key:value

匹配中可以使用andornot等boolean型操作

例如,想匹配所有minion中主机名(minion id)以webserv开头并且运行在Debian系统上或者minion的主机名(minion id)匹配正则表达式web-dc1-srv.*:

salt -C 'webserv* and G@os:Debian or E@web-dc1-srv.*' test.ping

top.sls中可以如下使用:

base:  'webserv* and G@os:Debian or E@web-dc1-srv.*':    - match: compound    - webserver



原创粉丝点击