设为首页 加入收藏

TOP

Saltstack_使用指南06_远程执行-指定目标(二)
2019-09-03 00:38:52 】 浏览:41
Tags:Saltstack_ 使用指南 06_ 远程 执行 指定 目标
bsp;operators.  【复合匹配的时候】

 

 1 # the following string matches all 「Debian minions」 with a hostname that begins with 「webserv」, as well as any minions that have a hostname which matches the regular expression 「web-dc1-srv.* 」:
 2 salt -C 'webserv* and G@os:Debian or E@web-dc1-srv.*' test.ping
 3 
 4 # Excluding a minion based on its ID is also possible:
 5 salt -C 'not web-dc1-srv' test.ping
 6 
 7 # Versions prior to 2015.8.0 a leading 「not」 was not supported in compound matches. Instead, something like the following was required:
 8 salt -C '* and not G@kernel:Darwin' test.ping
 9 
10 # Excluding a minion based on its ID was also possible:
11 salt -C '* and not web-dc1-srv' test.ping

 

7.1. 在 top file 中的使用

1 base:
2   'webserv* and G@os:Debian or E@web-dc1-srv.*':
3     - match: compound  # 复合匹配
4     - webserver

 

7.2. 优先匹配

1 # 可以使用括号实现优先匹配
2 # 一定要注意括号和目标之间需要「空格」。不遵守此规则可能导致错误的目标!
3 salt -C '( ms-1 or G@id:ms-3 ) and G@id:ms-3' test.ping

 

7.3. 替换分隔符

1 # 默认为 「:」 改为其他字符分割
2 salt -C 'J|@foo|bar|^foo:bar$ or J!@gitrepo!https://github.com:example/project.git' test.ping

 

案例1

 1 [root@salt100 ~]# salt -C 'G@os:redhat03' test.ping
 2 salt01:
 3     True
 4 [root@salt100 ~]# 
 5 [root@salt100 ~]# salt -C 'G|@os|redhat03' test.ping  # 将分隔符从「:」 改为「| 6 salt01:
 7     True
 8 [root@salt100 ~]# salt -C 'G!@os!redhat03' test.ping  #将分隔符从「:」 改为「! 9 salt01:
10     True
11 [root@salt100 ~]# salt -C 'G!@os!redhat03 or salt02' test.ping 
12 salt02:
13     True
14 salt01:
15     True

 

案例2

 1 [root@salt-master-7 ~]# salt '*' pillar.item getos
 2 10.0.0.112:
 3     ----------
 4     getos:
 5         ----------
 6         apache:
 7             httpd
 8         git:
 9             git
10 172.16.1.111:
11     ----------
12     getos:
13         ----------
14         apache:
15             apache2:kkk
16         git:
17             git-core
18 salt-master-7:
19     ----------
20     getos:
21         ----------
22         apache:
23             httpd
24         git:
25             git
26 [root@salt-master-7 ~]# salt -I 'getos:apache:apache2:kkk' test.ping
27 172.16.1.111:
28     True
29 [root@salt-master-7 ~]# salt -C 'I@getos:apache:apache2:kkk' test.ping    # 因为有 apache2:kkk ,所以在某些情况下会出现错误 
30 172.16.1.111:
31     True
32 [root@salt-master-7 ~]# 
33 [root@salt-master-7 ~]# salt -C 'I#@getos#apache#apache2:kkk' test.ping   # 表示使用 # 作为分隔符,而不是 : 
34 172.16.1.111:
35     True

 

8. 节点组(-N)

备注:

1 1、当向主配置文件添加或修改节点组时,必须重新启动master,以便完全识别这些更改。
2 2、在不重启的情况下,可以使用命令行中 -N 作为目标的有限功能。

 

8.1. /etc/salt/master 配置

 1 # The nodegroups master config file parameter is used to define nodegroups. Here's an example nodegroup configuration within 「/etc/salt/master」:
 2 nodegroups:
 3   group1: 'L@foo.domain.com,bar.domain.com,baz.domain.com or bl*.domain.com'
 4   group2: 'G@os:Debian and foo.domain.com'
 5   group3: 'G@os:Debian and N@group1'
 6   group4:
 7     - 'G@foo:bar'
 8     - 'or'
 9     - 'G@foo:baz'
10 
11 # As of the 2017.7.0 release of Salt, group names can also be prepended with a dash【破折号】. This brings the usage in line with many other areas of Salt. For example:
12 # 组节点也可以使用 如下方式。  组名前面到破折号「-13 nodegroups:
14   - group1: 'L@foo.domain.com,bar.domain.com,baz.domain.com or bl*.domain.com'
15 
16 注意:
17 Nodegroups可以参考group3中看到的其他Nodegroups,确保没有循环引用。循环引用将被检测到,并导致部分扩展产生日志错误消息。
18 注意:
19     「N@」 不能在命令行和top file中使用,只能在master config 中使用

 

8.2. 命令行匹配

salt -N group1 test.ping

 

8.3. 在 top file 中的使用

1 base:
2   group1:
3     - match: nodegroup  # 使用节点组匹配
4     - webserver
首页 上一页 1 2 3 下一页 尾页 2/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇阿里云linux服务器打开端口号 下一篇阿里云CentOS自动备份MySql 8.0并..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目