SaltStack practice: remotely execute Targeting and saltstacktargeting
Remote Execution of SaltStack-Targeting
@ (Learning) [SaltStack]
Remote Execution of SaltStack-Targeting
Minion id configure Targeting category
SaltStack remote execution components:
* Targeting)
* Module)
* Return (Returnners)
1. minion id Configuration
Minion id can be defined in the minion configuration file. If not defined, hostname is used by default. Minion id cannot be changed because the minion and master Public Key are named after minion id.
[Root @ salt-master111 pillar] # vim/etc/salt/minion
id: salt-master111
The more detailed the Minion id naming rules are, the more accurate the minion id is.
2. Targeting Classification
It is related to the Minion ID and needs to use the Minion ID:
* Globbing (wildcard)
* Regex (regular expression)
* List)
Wildcard match
[root@salt-master111 pillar]# salt "10.1.0.*" test.ping 10.1.0.112: True10.1.0.95: True10.1.0.50: True10.1.0.96: True[root@salt-master111 pillar]# salt "10.1.0.[!1]*" test.ping 10.1.0.95: True10.1.0.50: True10.1.0.96: True
Regular Expression matching
[root@salt-master111 pillar]# salt -E "10.1.0.(95|96)" test.ping 10.1.0.95: True10.1.0.96: True
List matching
[root@salt-master111 pillar]# salt -L "10.1.0.95,10.1.0.96" test.ping 10.1.0.95: True10.1.0.96: True
It is independent of Minion ID and does not involve Minion ID:
* Subnet/IP Address
* Grains
* Pillar
* Compound matchers (composite match)
* Node groups (Node group)
* Batching execution (batch execution)
IP address match
[root@salt-master111 pillar]# salt -S "10.1.0.50" test.ping 10.1.0.50: True
Grains match
[root@salt-master111 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 match
[root@salt-master111 salt]# salt -I "Zabbix_Server:10.1.0.111" test.ping10.1.0.112: True
Compound match
| Letter |
Match Type |
For example: |
Alt Delimiter? |
| G |
Grains glob |
G @ OS: Ubuntu |
Yes |
| E |
PCRE Minion ID |
E @ web \ d + \. (dev | qa | prod) \. loc |
No |
| P |
Grains PCRE |
P @ OS :( RedHat | Fedora | CentOS) |
Yes |
| L |
List of minions |
L@minion1.example.com, minion3.domain.com or bl * .domain.com |
No |
| I |
Pillar glob |
I @ pdata: foobar |
Yes |
| J |
Pillar PCRE |
J @ pdata: ^ (foo | bar) $ |
Yes |
| S |
Subnet/IP address |
S@192.168.1.0/24 or S@192.168.1.100 |
No |
| R |
Range cluster |
R @ % foo. bar |
No |
Matchers can be joined using boolean and, or, and not operators.
[root@salt-master111 salt]# salt -C "G@os:CentOS and S@10.1.0.112" test.ping 10.1.0.112: True[root@salt-master111 salt]#
Nodgroups
Nodegroups master configuration file parameters are used to define node groups. Here is an example of configuring a node group through the/etc/salt/master configuration file:
#nodegroups:# group1: 'L@foo.domain.com,bar.domain.com,baz.domain.com or bl*.domain.com'# group2: 'G@os:Debian and foo.domain.com'# group3: 'G@os:Debian and N@group1'# group4:# - 'G@foo:bar'# - 'or'# - 'G@foo:baz'nodegroups: test112: '10.1.0.112'
[root@salt-master111 ~]# salt -N 'test112' test.ping 10.1.0.112: True[root@salt-master111 ~]#
Batch execution
[root@salt-master111 salt]# salt '*' -b 2 test.ping
1
In top. sls, match the regular expression with grains:
"10.1.0.(95|96)": - match: pcre - apache "os:CentOS": - match: grain - apache