saltstack的探索-salt指定目标和分组

一、探讨一下,如何针对指定的minion id来执行
先了解官网文档的targeting这一节的内容:
TargetingSalt allows for minions to be targeted based on a wide range of criteria. The default targeting system uses globular expressions to match minions, hence if there are minions named larry1, larry2, curly1, and curly2, a glob of larry* will match larry1 and larry2, and a glob of *1 will match larry1 and curly1.Many other targeting systems can be used other than globs, these systems include:Regular Expressions
Target using PCRE-compliant regular expressions
Grains
Target based on grains data: Targeting with Grains
Pillar
Target based on pillar data: Targeting with Pillar
IP
Target based on IP address/subnet/range
Compound
Create logic to target based on multiple targets: Targeting with Compound
Nodegroup
Target with nodegroups: Targeting with Nodegroup二、通配符和正则5.1 Matching the minion id
5.1.1 Globbing
The default matching that Salt utilizes is shell-style globbing around the minion id. This also works for states in the top file.
Note: You must wrap salt calls that use globbing in single-quotes to prevent the shell from expanding the globs before Salt is invoked.
Match all minions:salt ’*’ test.pingMatch all minions in the example.net domain or any of the example domains:salt ’*.example.net’ test.ping
salt ’*.example.*’ test.pingMatch all the webN minions in the example.net domain (web1.example.net, web2.example.net . . . webN.example.net):salt ’web?.example.net’ test.pingMatch the web1 through web5 minions:salt ’web[1-5]’ test.pingMatch the web-x, web-y, and web-z minions:salt ’web-[x-z]’ test.ping5.1.2 Regular Expressions
Minions can be matched using Perl-compatible regular expressions (which is globbing on steroids and a ton of caf-feine).
Match both web1-prod and web1-devel minions:salt -E ’web1-(prod|devel)’ test.pingWhen using regular expressions in a State’s top file, you must specify the matcher as the first option. The following example executes the contents of webserver.sls on the above-mentioned minions.base:’web1-(prod|devel)’:- match: pcre- webserver5.1.3 Lists
At the most basic level, you can specify a flat list of minion IDs:salt -L ’web1,web2,web3’ test.ping三、Grains
我的理解:通过grains能得到系统底层的一些基本信息。是静态的。可以在master和minion的配置中写入key:value,但要注意优先级等区别。
还是翻官网文档先:
5.2 Grains
Salt comes with an interface to derive information about the underlying system. This is called the grains interface, because it presents salt with grains of information.
Grains Static bits of information that a minion collects about the system when the minion first starts.
The grains interface is made available to Salt modules and components so that the right salt minion commands are automatically available on the right systems.
It is important to remember that grains are bits of information loaded when the salt minion starts, so this informationis static. This means that the information in grains is unchanging, therefore the nature of the data is static. So grainsinformation are things like the running kernel, or the operating system.Match all CentOS minions:salt -G ’os:CentOS’ test.pingMatch all minions with 64-bit CPUs and return number of available cores:salt -G ’cpuarch:x86_64’ grains.item num_cpusAdditionally, globs can be used in grain matches, and grains that are nested in a dictionary can be matched by adding a colon for each level that is traversed. For example, the following will match hosts that have a grain called ec2_tags,which itself is a dict with a key named environment, which has a value that contains the word production:salt -G ’ec2_tags:environment:*production*’5.2.1 Listing Grains
Available grains can be listed by using the ‘grains.ls’ module:
salt ’*’ grains.lsGrains data can be listed by using the ‘grains.items’ module:
salt ’*’ grains.items5.2.2 Grains in the Minion Config
Grains can also be statically assigned within the minion configuration file. Just add the option grains and pass options to it:
grains:roles:- webserver- memcachedeployment: datacenter4cabinet: 13cab_u: 14-15Then status data specific to your servers can be retrieved via Salt, or used inside of the State system for matching. It also makes targeting, in the case of the example above, simply based on specific data about your deployment.5.2.3 Grains in /etc/salt/grains
If you do not want to place your custom static grains in the minion config file, you can also put them in /etc/salt/grains. They are configured in the same way as in the above example, only without a top-level grains: key:
roles:- webserver- memcache
deployment: datacenter4
cabinet: 13
cab_u: 14-15Precedence of Custom Static Grains
Be careful when defining grains both in /etc/salt/grains and within the minion config file. If a grain is defined in both places, the value in the minion config file takes precedence, and will always be used over its counterpart in /etc/salt/grains.5.2.4 Writing Grains
Grains are easy to write. The grains interface is derived by executing all of the “public” functions found in the modules located in the grains package or the custom grains directory. The functions in the modules of the grains must return a Python dict, where the keys in the dict are the names of the grains and the values are the values.
Custom grains should be placed in a _grains directory located under the file_roots specified by the mas-ter config file. They will be distributed to the minions when state.highstate is run, or by executing the
saltutil.sync_grains or saltutil.sync_all functions.
Before adding a grain to Salt, consider what the grain is and remember that grains need to be static data. If the data is something that is likely to change, consider using Pillar instead.
Examples of Grains
The core module in the grains package is where the main grains are loaded by the Salt minion and provides the principal example of how to write grains:
https://github.com/saltstack/salt/blob/develop/salt/grains/core.py
Syncing Grains
Syncing grains can be done a number of ways, they are automatically synced when state.highstate is called, or the grains can be synced and reloaded by calling the saltutil.sync_grains or saltutil.sync_all functions.四、Nodegroup
在master的配置文件/etc/salt/master 中:有如下一段:#####         Node Groups           #####
##########################################
# Node groups allow for logical groupings of minion nodes. A group consists of a group
# name and a compound target.
#nodegroups:
#  group1: 'L@foo.domain.com,bar.domain.com,baz.domain.com and bl*.domain.com'
#  group2: 'G@os:Debian and foo.domain.com'咱们继续看文档:
5.3 Node groups
Node group A predefined group of minions declared in the master configuration file nodegroups setting as a compound target.
Nodegroups are declared using a compound target specification. The compound target documentation can be found here:
Compound Matchers(参考下面一段)
For example, in the master config file nodegroups setting:nodegroups:
group1: ’L@foo.domain.com,bar.domain.com,baz.domain.com or bl*.domain.com’
group2: ’G@os:Debian and foo.domain.com’Specify a nodegroup via the -N option at the command-line:salt -N group1 test.pingSpecify a nodegroup with - match: nodegroup in a top file:
base:group1:- match: nodegroup- webserver实例:
# vim /etc/salt/master
nodegroups:cabinet01: 'E@test2(1[1-9]|3[1-2]).company.com'cabinet02: 'E@test(12|14[0-6]|18[3-5]).company.com'cabinet03: 'E@test10[1-5].company.com'# salt -N cabinet02 test.ping
test144.company.com:True
test183.company.com:True
test185.company.com:True
test146.company.com:True
test140.company.com:True
test143.company.com:True
test141.company.com:True
test145.company.com:True
test142.company.com:True
test12.company.com:True五、混合匹配
5.4 Compound matchers
Compound matcher A combination of many target definitions that can be combined with boolean operators.Compound matchers allow very granular minion targeting using any of the previously discussed matchers. The default matcher is a glob, as usual. For matching via anything other than glob, preface it with the letter denoting the match type. The currently implemented “letters” are:
Letter              Meaning                             Example
G                   Grains glob match                   G@os:Ubuntu
E                   PCRE Minion id match                E@web\d+\.(dev|qa|prod)\.loc
P                   Grains PCRE match                   P@os:(RedHat|Fedora|CentOS)
L                   List of minions                     L@minion1.example.com,minion3.domain.com or bl*.domain.com
I                   Pillar glob match                   I@pdata:foobar
S                   Subnet/IP addr match                S@192.168.1.0/24 or S@192.168.1.100
R                   Range cluster match                 R@%foo.bar
D                   Minion Data match                   D@key:valueMatchers can be joined using boolean and, or, and not operators.For example, the following command matches all minions that have a hostname that begins with “webserv” and that are running Debian or it matches any minions that have a hostname that matches the regular expression web-dc1-srv.
* :salt -C ’webserv* and G@os:Debian or E@web-dc1-srv.*’ test.pingThat same example expressed in a top file looks like the following:
base:’webserv* and G@os:Debian or E@web-dc1-srv.*’:- match: compound- webserverNote that you cannot have a leading not in a command. Instead you must do something like the following:
salt -C ’* and not G@kernel:Darwin’ test.ping实例:
[root@test200 ~]# salt -C 'E@test(12|14[0-6]|18[3-5]).company.com or dev0[1-2].office.com' test.ping
test144.company.com:True
test183.company.com:True
test185.company.com:True
test146.company.com:True
test140.company.com:True
test143.company.com:True
test141.company.com:True
test145.company.com:True
test142.company.com:True
test12.company.com:True
dev01.office.com:True
dev02.office.com:True

转载于:https://blog.51cto.com/nosmoking/1636508

saltstack的探索-salt指定目标和分组相关推荐

  1. python编写自定义函数计算一维numpy数组中与指定目标数值最接近(距离最近)的数值(find closest value in numpy array to a certain value)

    python编写自定义函数计算一维numpy数组中与指定目标数值最接近(距离最近)的数值(find closest value in numpy array to a certain value) 目 ...

  2. 来自数据源的 String 类型的给定值不能转换为指定目标列的类型 nvarchar。

    SqlBulkCopy 来自数据源的 String 类型的给定值不能转换为指定目标列的类型 nvarchar. 解决方法 1,首先检查数据库表的字段是否过小 2,检查数据中是否有类似单引号的数据,做一 ...

  3. Makefile中指定目标(MAKECMDGOALS)

    有一个 make 的环境变量叫"MAKECMDGOALS",这个变量中会存放你所指定的终极目标的列表,如果在命令行上,你没有指定目标,那么,这个变量是空值.这个变量可以让你使 用在 ...

  4. 连接宽带错误769:无法连接到指定目标

    连接宽带错误769:无法连接到指定目标 相关信息:找不到netcfg.hlp 原因:禁用了本地连接 解决方法:启用本地连接 Others 外行学电脑完全自学手册

  5. 因远程计算机不能及时反应 此连接已被终止,宽度连接不上提示:错误769无法连接到指定目标...

    今天阿权站长的宽度突然连接不上提示:错误769无法连接到指定目标.点击详情的时候提示:找不到文件netcfg.hlp是否亲自查找该文件!找了好久才发现原来是本地连接没有打开.解释下netcfg.hlp ...

  6. ES分组聚合:计算每个tag下的商品数量且某个filed包含指定关键字,分组,平均,每个tags下的平均价格,排序,指定范围区间

    1.第一个分析需求:计算每个tag下的商品数量 GET /ecommerce/product/_search {"aggs": {"group_by_tags" ...

  7. 大规模数据存储集群数据存放的设计,分布式shardid的生成 - 如何指定范围随机数, 分组随机数...

    标签 PostgreSQL , 分组ID生成 , 生成哈希映射 , sharding , shard 背景 在一些分布式数据库系统中,通常会有多个数据节点,用户的数据分布策略通常有一致性哈希.按列哈希 ...

  8. apache 编译java_关于apache的bsf包的JavaUtils工具类包自定义类编译器对指定目标文件进行编译JDKcompile...

    一.前言 关于apache的bsf源码包中的org.apache.bsf.util.JavaUtils工具类,对指定类文件进行编译生成二进制class目标文件JDKcompile,详情见源码说明. 二 ...

  9. 计算机科学与探索类别,图像目标类别检测综述-计算机科学与探索.pdf

    图像目标类别检测综述-计算机科学与探索 蔡 强,刘亚奇,曹 健,等.图像目标类别检测综述[J].计算机科学与探索,2015 ,9(3 ):257-265. ISSN 1673-9418 CODEN J ...

最新文章

  1. IIS6.0发布后对路径“D:\xxx\xxxx\web.config”的访问被拒绝问题的解决方法
  2. 深度学习近似建模,助力飞越「维数灾难」温度场
  3. svn 主干(trunk)、分支(branch )、标记(tag) 简介
  4. AGC056E-Cheese【dp】
  5. 使用 ssh 命令来访问(登录/连接)远程服务器主机
  6. AAC ADTS格式分析
  7. Linux学习:第五章-Linux用户和用户组管理
  8. Addressable系统的加载资源API总结
  9. 【RN6752】模拟高清AHD芯片或成为车机新标配
  10. Seaborn学习笔记4
  11. ali 媒体转码签名生成-php
  12. .net 简单的后台合成图片
  13. Proxmox Mail Gateway (PMG) 安装及简单设置
  14. android 页面边框设置
  15. python怎么制作游戏存档功能,如何在Python中创建目录的zip存档?
  16. MySQL 的 20+ 条最佳实践
  17. SRE重案调查组 第二集 | 挖掘应用处理变慢的“真相”
  18. 【操作系统】第十二章-保护和安全
  19. 真正让你明白Hive调优系列3:笛卡尔乘积,小表join大表,Mapjoin等问题
  20. 洗衣粉等日化用品将受油价高企影响涨价

热门文章

  1. 并发教程--JAVA5中 计数信号量(Counting Semaphore)例子
  2. 【学习OpenCV4】什么是图像的直方图?如何获取直方图?
  3. 【OpenCV】图像旋转详解,边缘用黑色填充
  4. IMU-Allan方差分析
  5. 为什么其他计算机连接需要密码是什么东西,连接其他电脑需要密码怎么处理
  6. 搜索接口php,【微信公众平台开发】百度周边搜索接口php封装
  7. python _winreg 操作注册表
  8. 使用HTML注释标签,超详细的HTML !–…– 注释标签使用实例.pdf
  9. 计算尖峰电流的目的_干货 | 谈谈RCD的计算方法
  10. python 爬虫论_Python网络爬虫(理论篇)