1. 程式人生 > >SaltStack實戰之遠程執行-Targeting

SaltStack實戰之遠程執行-Targeting

saltstack

SaltStack實戰之遠程執行-Targeting


學習 SaltStack



  • SaltStack實戰之遠程執行-Targeting

    • 1. minion id配置

    • 2. Targeting分類


SaltStack遠程執行組成部分:

  • 目標(Targeting)

  • 模塊(Module)

  • 返回(Returnners)

1. minion id配置

minion id可以定義在minion配置文件中,如果未定義,默認使用的是hostname。minion id是不能變動的,因為minion與master認證公鑰是以minion id命名文件名的。
[[email protected] pillar]# vim /etc/salt/minion

id: salt-master111

Minion id命名越規範越詳細,在使用minion id匹配過程中就越準確。

2. Targeting分類

和Minion ID有關,需要使用Minion ID:

  • Globbing(通配符)

  • regex(正則表達式)

  • List(列表)

通配符匹配

[[email protected] pillar]# salt "10.1.0.*" test.ping  
10.1.0.112:
True
10.1.0.95:
True
10.1.0.50:
True
10.1.0.96:
True
[[email protected] pillar]# salt
"10.1.0.[!1]*" test.ping
10.1.0.95:
True
10.1.0.50:
True
10.1.0.96:
True

正則匹配

[[email protected] pillar]# salt -E "10.1.0.(95|96)" test.ping  
10.1.0.95:
True
10.1.0.96:
True

列表匹配

[[email protected] pillar]# salt -L "10.1.0.95,10.1.0.96" test.ping       
10.1.0.95:
True
10.1.0.96:
True

和Minion ID無關,不涉及到Minion ID:

  • 子網/IP地址

  • Grains

  • Pillar

  • Compound matchers(復合匹配)

  • Node groups(節點組)

  • Batching execution(批處理執行)

IP地址匹配

[[email protected] pillar]# salt -S "10.1.0.50" test.ping       
10.1.0.50:
True

Grains匹配

[[email protected] pillar]# salt -G "os:CentOS" test.ping          
10.1.0.95:
True
10.1.0.112:
True
10.1.0.50:
True
salt-master111:
True
10.1.0.96:
True

Pillar匹配

[[email protected] salt]# salt -I "Zabbix_Server:10.1.0.111" test.ping
10.1.0.112:
True

復合匹配

LetterMatch Type例如:Alt Delimiter?
GGrains glob[email protected]:UbuntuYes
EPCRE Minion ID[email protected]\d+\.(dev|qa|prod)\.locNo
PGrains PCRE[email protected]:(RedHat|Fedora|CentOS)Yes
LList of minions[email protected],minion3.domain.com or bl*.domain.comNo
IPillar glob[email protected]:foobarYes
JPillar PCRE[email protected]:^(foo|bar)$Yes
SSubnet/IP address[email protected]/24 or [email protected]No
RRange clusterR@%foo.barNo

Matchers can be joined using boolean and, or, and not operators.

[root@salt-master111 salt]# salt -C "[email protected]:CentOS and [email protected]" test.ping   
10.1.0.112:
True
[root@salt-master111 salt]#

Nodgroups

nodegroups master配置文件參數用於定義節點組。這裏有一個通過/etc/salt/master配置文件配置節點組的例子:

#nodegroups:
# group1: [email protected],bar.domain.com,baz.domain.com or bl*.domain.com‘
# group2: [email protected]:Debian and foo.domain.com‘
# group3: [email protected]:Debian and [email protected]
# group4:
# - [email protected]:bar‘
# - ‘or‘
# - [email protected]:baz‘
nodegroups:
test112: ‘10.1.0.112‘
[root@salt-master111 ~]# salt -N ‘test112‘ test.ping           
10.1.0.112:
True
[root@salt-master111 ~]#

批處理執行

[root@salt-master111 salt]# salt ‘*‘ -b 2 test.ping

在top.sls中,使用正則和grains匹配寫法:

  "10.1.0.(95|96)":
- match: pcre
- apache

"os:CentOS":
- match: grain
- apache

其它targeting詳情:http://docs.saltstack.cn/topics/targeting/index.html


本文出自 “ygqygq2” 博客,請務必保留此出處http://ygqygq2.blog.51cto.com/1009869/1933470

SaltStack實戰之遠程執行-Targeting