saltstack(二)target
2016-04-05 14:49
337 查看
saltstack_target格式
<args>显而易见gcc就是传给pkg.insatlled这个函数的参数
<function>和<args>这些个东西都比较简单,大头是<target>,其实<function>也不简单,这么多模块全搞会也挺难的。
<target>是个什么东西呢?望文生义,没错,就是目标,也就是我们minion的id。我们要执行的函数或者命令,将要作用在哪些机器上面。
楼主在官网和doc里面查了下,大概有以下几种匹配方式。
glob(default):"*minion"
PCRE:"web[1-4](apache|nginx)"
List:"minion1,minion2,minion3"
Grans:"os:Debian"
Gran PCRE:'os:(Debian|CentOs)'
NodeGroup:(defined in master config file)
Pillar:'test:test'
Subnet:10.0.0.1/24
compound:混合方式
-X, --exsel
下面就举个例子看一看
第
1种方式glob听起来不太懂,其实就shell-style,shell里能用的,它也就能用。为啥叫它glob呢,因为它是默认的,用它的时候不用加
参数,用别人的时候,要加上参数才成,比如用正则表达式要用salt -E,用列表要用salt -L。官网上有几个例子,我记录一下。
6种方式,定义Group组,前面的几种方式定义minion都可以用在这里面,如果用列表的话,写成这样就可以了
L@minion1,minion2,minion3,用Granin匹配的话写成G@oscodename:Wheezy,当然也可以用and,or做
进一步匹配
下面的webs就是一个组,用到了列表,和Grains和or
salt <target> <function> <args>举个例子,安装个gcc
salt \* pkg.installed gcc<function>就是pkg.installed这东西,说的详细点应该是pkg这东西是个python模块,installed才是里面定义的一个具体干活的函数。
<args>显而易见gcc就是传给pkg.insatlled这个函数的参数
<function>和<args>这些个东西都比较简单,大头是<target>,其实<function>也不简单,这么多模块全搞会也挺难的。
<target>是个什么东西呢?望文生义,没错,就是目标,也就是我们minion的id。我们要执行的函数或者命令,将要作用在哪些机器上面。
楼主在官网和doc里面查了下,大概有以下几种匹配方式。
glob(default):"*minion"
PCRE:"web[1-4](apache|nginx)"
List:"minion1,minion2,minion3"
Grans:"os:Debian"
Gran PCRE:'os:(Debian|CentOs)'
NodeGroup:(defined in master config file)
Pillar:'test:test'
Subnet:10.0.0.1/24
compound:混合方式
-X, --exsel
下面就举个例子看一看
第
1种方式glob听起来不太懂,其实就shell-style,shell里能用的,它也就能用。为啥叫它glob呢,因为它是默认的,用它的时候不用加
参数,用别人的时候,要加上参数才成,比如用正则表达式要用salt -E,用列表要用salt -L。官网上有几个例子,我记录一下。
salt "*" test.ping //这个匹配所有minion salt "*minion" test.ping //这个匹配所有以minion结尾的minion salt "salt?minion" test.ping //这里面的?匹配任意一个字符 salt "web[1-5]" test.ping //匹配web1,web2,web3,web4,web5 salt "web[1,3]" test.ping //匹配web1,web3 salt "web[a-c]" test.ping //匹配weba,webb,webc第2种方式,可以用正则表达式去匹配minion id,我自己选了几个正则测了一下
root@salt-master:~# salt -E "salt-minio." test.ping salt-minion: True root@salt-master:~# root@salt-master:~# salt -E "salt-minio*" test.ping salt-minion: True root@salt-master:~# root@salt-master:~# salt -E "salt(-|~)minion" test.ping salt-minion: True root@salt-master:~# root@salt-master:~# salt -E "^salt" test.ping salt-minion: True第3种方式,是列表的方式,有啥都罗列出来就OK了
salt -L "minion1,minion2,minion3" test.ping第4种方式,是根据Grain匹配,Grain是个啥,下一篇再写吧
salt -G 'oscodename:Wheezy' test.ping第5种方式是,Grain和PCRE匹配的混合
salt -grain-pcre 'oscodename:(Wheezy|Squeeze)' test.ping第
6种方式,定义Group组,前面的几种方式定义minion都可以用在这里面,如果用列表的话,写成这样就可以了
L@minion1,minion2,minion3,用Granin匹配的话写成G@oscodename:Wheezy,当然也可以用and,or做
进一步匹配
下面的webs就是一个组,用到了列表,和Grains和or
root@salt-master:~# sed -n '583,584p' /etc/salt/master nodegroups: webs: 'L@minion1,minion2,minion3 or G@oscodename:Wheezy' root@salt-master:~# root@salt-master:~# /etc/init.d/salt-master restart [ ok ] Restarting salt master control daemon: salt-master. root@salt-master:~# salt -N "webs" test.ping salt-minion: True root@salt-master:~#第7种方式,根据pillar匹配,pillar下一篇再写。先来个例子
root@salt-master:~# salt -I 'apache:apache2' test.ping salt-minion: True root@salt-master:~#第8种方式,可以根据minion所在的子网,来匹配minion
root@salt-master:~# salt -S "10.240.160.0/24" test.ping salt-minion: True root@salt-master:~#第9种方式,这个其实是个混合方式,前面的几种都可以用,还可以用and,or连接起来
root@salt-master:~# salt -C 'G@os:RedHat or L@salt-minion,minion1' test.ping salt-minion: True root@salt-master:~#
相关文章推荐
- 详解Android中Handler的实现原理
- Base64编码(原理)
- 模糊测试工具-peachFuzzer
- 关于JavaScript与HTML的交互事件
- 101/103/104规约应用典型问题例举
- 【SQL查询日志】查看数据库历史查询记录
- 【翻译】Ext JS最新技巧——2014-5-12
- 博客收集
- Thinkphp基于规则的Auth权限认证类
- 常用AngularJs代码段
- valgrind
- 出生日期转年龄
- 常用AngularJs代码段
- 目标检测中背景建模方法
- ssh整合时struts出现unknown location的问题
- 一种SPA(单页面应用)架构
- 图像的傅里叶变换
- WCF入门教程3——WCF通信模式
- [国嵌攻略][178][网络安全传输系统框架搭建]
- iOS FMDB数据库的增删改查