saltstack正则简单匹配

远程执行第三功能,输出!可以写入到数据库里,文件里!

匹配ID:
正则表达式:
不同的匹配方式需要加不同参数!

-E:正则
-L:列出,多个用逗号分隔,
-G: grain
-N: 节点组
-R: 范围
-C:混合
-I:pillar
-S: ipv4 子网掩码的形式

salt ‘*.doam.net’ test.ping--------匹配以*.doam.net的
salt ‘*.doam.*’ test.ping----------匹配中间为doam的
salt ‘web?.doam.*’ test.ping-------一个问号表示统配一个,多个表示通赔多个
salt ‘web[1-5]’ test.ping----------1-5,通赔以web开头的1-5的id
salt ‘web[1,3]’ test.ping---------统配以web开头,1和3的id
salt ‘web[x-z]’ test.ping----------统配以web开头,x到z结尾的id

如下:

[root@master ~]# salt '*' test.ping
minios.10.0.0.8.com:
    True
[root@master ~]# salt '*.10.0.0.8.*' test.ping
minios.10.0.0.8.com:
    True
[root@master ~]# salt 'minios.10.0.0.8.*' test.ping
minios.10.0.0.8.com:
    True

我们添加一台新的测试:

[root@master ~]# salt-key 
Accepted Keys:
minios.10.0.0.8.com
Denied Keys:
Unaccepted Keys:
minion-node11.10.0.0.11.com
Rejected Keys:
[root@master ~]# salt-key -a minion-node11.10.0.0.11.com
The following keys are going to be accepted:
Unaccepted Keys:
minion-node11.10.0.0.11.com
Proceed? [n/Y] y       
Key for minion minion-node11.10.0.0.11.com accepted.
[root@master ~]# salt-key 
Accepted Keys:
minion-node11.10.0.0.11.com
minios.10.0.0.8.com
Denied Keys:
Unaccepted Keys:
Rejected Keys:
[root@master ~]# salt '*' test.ping
minios.10.0.0.8.com:
    True
minion-node11.10.0.0.11.com:
    True
[root@master ~]# 

匹配上面两个主机名:
-E测试

[root@master ~]# salt -E '(minios|minion-node11)'.10.0.0.*.com test.ping
minios.10.0.0.8.com:
    True
minion-node11.10.0.0.11.com:
    True
[root@master ~]# 

修改top.sls下发测试

[root@master ~]# vim /etc/salt/status/top.sls 
base:

  '(minios|minion-node11).10.0.0.*.com': ------->匹配以minios主机和minion-node11主机.10.0.0.*.com
    - match: pcre ------------------------------>正则表达式必选项
    - init.pkg
    - init.conf
~                 

执行前几章的安装包和配置文件

[root@master ~]# salt '*' state.highstate
minion-node11.10.0.0.11.com:
----------
          ID: pkg.init
    Function: pkg.installed
        Name: sl
      Result: True
     Comment: The following packages were installed/updated: sl
     Started: 07:55:48.875688
    Duration: 21309.13 ms
     Changes:   
              ----------
              sl:
                  ----------
                  new:
                      5.02-1.el6
                  old:
----------
          ID: conf-config
    Function: file.managed
        Name: /etc/security/limits.conf
      Result: True
     Comment: File /etc/security/limits.conf updated
     Started: 07:56:10.188457
    Duration: 54.812 ms
     Changes:   
              ----------
              diff:
                  ---  
                  +++  
                  @@ -39,8 +39,8 @@
                   #<domain>      <type>  <item>         <value>
                   #
                   
                  -#*               soft    core            0
                  -#*               hard    rss             10000
                  +*               soft    core            0
                  +*               hard    rss             10000
                   #@student        hard    nproc           20
                   #@faculty        soft    nproc           20
                   #@faculty        hard    nproc           50
                  @@ -48,3 +48,4 @@
                   #@student        -       maxlogins       4
                   
                   # End of file
                  +*-nofile65535

Summary
------------
Succeeded: 2 (changed=2)
Failed:    0
------------
Total states run:     2

minios.10.0.0.8.com:
    Minion did not return. [No response] -------------------->这里有问题,提示没有返回信息!暂时忽略他
[root@master ~]# 

ID号命名:
角色-node1.业务(web).idc1.域名.com
如:
nginx-node1.web.idc1.linuxea.com

以及IP地址也可

-L
[root@master ~]# salt -L 'minion-node11.10.0.0.11.com,minios.10.0.0.8.com' test.ping
minios.10.0.0.8.com:
    True
minion-node11.10.0.0.11.com:
    True
[root@master ~]# 

-S
[root@master ~]# salt -S '10.0.0.0/24' test.ping
minios.10.0.0.8.com:
    True
minion-node11.10.0.0.11.com:
    True
[root@master ~]# 

1 分享

您可以选择一种方式赞助本站

支付宝扫码赞助

支付宝扫码赞助

日期: 2015-12-12分类: saltstack

标签: saltstack

发表评论