SaltStack实战之远程执行-Targeting

SaltStack实战之远程执行-Targeting

学习 SaltStack

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:    True10.1.0.95:    True10.1.0.50:    True10.1.0.96:    True[[email protected] pillar]# salt "10.1.0.[!1]*" test.ping 10.1.0.95:    True10.1.0.50:    True10.1.0.96:    True

正则匹配

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

列表匹配

[[email protected] pillar]# salt -L "10.1.0.95,10.1.0.96" test.ping       10.1.0.95:    True10.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:    True10.1.0.112:    True10.1.0.50:    Truesalt-master111:    True10.1.0.96:    True

Pillar匹配

[[email protected] salt]# salt -I "Zabbix_Server:10.1.0.111" test.ping10.1.0.112:    True    

复合匹配

Letter Match Type 例如: Alt Delimiter?
G Grains glob [email protected]:Ubuntu Yes
E PCRE Minion ID [email protected]\d+\.(dev|qa|prod)\.loc No
P Grains PCRE [email protected]:(RedHat|Fedora|CentOS) Yes
L List of minions [email protected],minion3.domain.com or bl*.domain.com No
I Pillar glob [email protected]:foobar Yes
J Pillar PCRE [email protected]:^(foo|bar)$ Yes
S Subnet/IP address [email protected]/24 or [email protected] No
R Range cluster [email protected]%foo.bar No

Matchers can be joined using boolean andor, 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

时间: 2024-08-03 08:22:27

SaltStack实战之远程执行-Targeting的相关文章

SaltStack实战之SaltStack快速入门

SaltStack实战之SaltStack快速入门 1. SaltStack介绍 1.1 SaltStack常用网址 1.2 SaltStack运行方式 1.3 SaltStack三大功能 2. SaltStack部署 2.1 SaltStack master配置 2.2 SaltStack minion配置 2.3 SaltStack认证 2.4 saltsatck远程执行 2.5 saltsatck配置管理 1. SaltStack介绍 Salt,一种全新的基础设施管理方式,部署轻松,在几分

2、自动化运维之SaltStack远程执行详解

SaltStack远程执行详解 ●目标(Targeting) ●模块(Module) ●返回(Returnners) 混合模式-C 选项 主机名设置参照: redis-node1-redis03-idc04-soa.example.com(电商) 1.1模块介绍 [[email protected] salt]# salt '*' service.available sshd linux-node1.zhurui.com: True linux-node2.zhurui.com: True 服务

saltstack之远程执行

#########################################TARGETING############################################ [[email protected] pillar]# salt '*' cmd.run 'w' linux-node1.example.com: 09:22:01 up 37 min,  1 user,  load average: 0.00, 0.01, 0.06 USER     TTY      FR

Saltstack远程执行(四)

Saltstack远程执行 语法例:salt '*' cmd.run 'w' -  命令:salt -  目标:'*' -  模块:cmd.run,自带150+模块,也可以自己写模块 -  返回:执行后结果返回,Returnners组件 1.指定目标(targeting) 官网文档:https://docs.saltstack.com/en/latest/topics/targeting/index.html 两种定位方法:一种和minion ID有关,一种和monion ID无关 1)mini

SaltStack(三) 远程执行

一.简单测试 在前面3个小节我们介绍了SaltStack并且讲解了Salt的安装部署.相信你现在已经只有拥有一个Master和至少一个Minion.我们能做点什么呢?下面的两个章节,带领读者快速的使用SaltStack的远程执行和配置管理功能. 远程执行时SaltStack的核心功能之一.主要使用salt模块可以批量给选定的Minion端执行相应的命令,并获得返回结果.让我们执行第一个Salt命令. [[email protected] ~]# salt '*' test.ping salt-c

SaltStack 的远程执行机制

:first-child { margin-top: 0; } blockquote > :last-child { margin-bottom: 0; } img { border: 0; max-width: 100%; height: auto !important; margin: 2px 0; } table { border-collapse: collapse; border: 1px solid #bbbbbb; } td, th { padding: 4px 8px; bord

SaltStack安装配置与远程执行测试

SaltStack是基于Python开发的服务器基础架构集中管理平台,也称为自动化运维工具,具备远程执行.配置管理.云管理三大功能.管理端称为Master,被管理端称为Minion,Master和Minion通过密钥认证进行加密通信,通过消息队列软件ZeroMQ进行内容传输,使用的默认端口为4505和4506.本文的主要内容为SaltStack的安装配置与远程执行测试. 一.环境准备 1.使用3台Redhat 6.5的服务器,分别是: salt-master:192.168.10.120 sal

一 saltstack 数据系统 远程执行

saltstack总结 官方中文网站 官方英文网站 1. 简介 三大功能 远程执行 配置管理 云管理 四种运行方式 local master / minion c/s模式(常用) syndic - (相当于zabbix proxy) salt ssh 2. 安装 1. 环境声明 系统版本和内核: CentOS Linux release 7.2.1511 (Core) 3.10.0-327.el7.x86_64 基础环境: salt-master 10.0.0.204 salt-minion 1

saltstack在windows客户端远程执行脚本提示路径不对的问题

saltstack在windows客户端远程执行脚本提示路径不对的问题 环境: salt-master ==2018.3.0 salt-minion ==2018.3.0 python== 2.7.5 centos==7 问题描述: salt有个远程执行命令的模块cmd.script,在使用该模块时,出现错误: salt 'minion-id' cmd.script salt://test.ps1 shell=powershell 其中salt://为/etc/salt.conf定义的base路