[关闭]
@cdmonkey 2016-07-08T09:15:51.000000Z 字数 1542 阅读 1040

Saltstack(2)目标匹配

Saltstack


此处输入图片的描述

一、Remote Execution

作为Master端,首先需要指定根目录(File root),然后于基础(Base)场景中创建入口文件top.sls,再依据该文件中的内容或者说是映射关系找到对应的状态文件。

于远程主机运行预定义或任意的命令,即远程执行,这是核心功能。

  1. # Command Syntax:
  2. salt <target> module.method <parameter>

远程执行的三大功能:

1. Target

http://docs.saltstack.cn/topics/tutorials/modules.html#target
http://www.tuicool.com/articles/BbMVbi
默认是通过标识(Minion ID)进行匹配的。而无论采用什么样的目标匹配写法,该写法于top.sls中都同样适用。

matching.png-10.6kB

Globbing

如前所述,默认对目标的匹配是通过对节点标识使用通配符(Globbing)进行匹配的。具体示例可参阅官方文档。如果使用通配符,那么salt指令无需使用任何的命令选项。

http://docs.saltstack.cn/topics/targeting/globbing.html#globbing

Regular

使用正则进行匹配。
http://docs.saltstack.cn/topics/targeting/globbing.html#regular-expressions

  1. [root@salt-master ~]# salt -E 'node(2|3).cdmonkey.com' test.ping
  2. node2.cdmonkey.com:
  3. True
  4. node3.cdmonkey.com:
  5. True

如果于top.sls文件中使用正则表达式,那么需要明确地指出对于目标的匹配使用的是正则表达式:

  1. base:
  2. 'node(2|3).cdmonkey.com':
  3. - match: pcre # Represents the use of regular expressions matching
  4. - init.pkg
  5. - init.limit

注意:如果被控端标识比较合理并且详细,那么仅仅使用通配符及正则表达式就可以对目标进行很精确的匹配。

List

很简单,但不常用,所以不多说了。

  1. [root@salt-master ~]# salt -L 'node2.cdmonkey.com,node3.cdmonkey.com' test.ping
  2. node2.cdmonkey.com:
  3. True
  4. node3.cdmonkey.com:
  5. True

Subnet & IP Address

使用网络地址进行匹配。
http://docs.saltstack.cn/topics/targeting/ipcidr.html

  1. [root@salt-master ~]# salt -S '172.16.1.0/24' test.ping
  2. node2.cdmonkey.com:
  3. True
  4. node3.cdmonkey.com:
  5. True

2. Module

http://docs.saltstack.cn/ref/modules/all/index.html
模块按功能分为两种:一种用于远程执行,一种用于状态同步,且并不能交叉使用。而远程执行模块是核心。

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注