This article summarizes how saltstack locates the target host and introduces some common examples.
> Why do I need to locate the host?
As a configuration management software, the first thing to solve is how to determine the push host, or the push target of a specific configuration. If you cannot determine the target of one or more pushes, how can we automate the classification configuration management of a large number of hosts?
> What is the target mechanism of saltstack?
Saltstack has established a complete minion positioning mechanism. The official term "target minions" specifies attributes of a minion in multiple ways (for example, matching a regular expression with a minion ID or a specific grains attribute of a minion) to differentiate the target of the push command or status. The following describes how to match the host provided by salt:
Globbing (default matching method, Linux Shell-style wildcard)
Perl-Compatible Regular Expressions (E, that is, the regular expression matching method, and the object is also minion ID)
Lists (L, directly a list of minion IDs)
Grains (G/P, using grains value matching, P is using regular expression matching, G is the default wildcard mode .)
Nodegroup (n, the predefined group information in the master configuration file)
Subnet (S, matching using the IP attribute of minion)
Range cluster (R, Set range server feedback value matching? Not understood yet)
Pillar (I, simple, matching with pillar data)
Compound (C, combination matching method, one or more of the above methods of joint matching)
Some common target examples:
Salt '*' test. ping-vsalt 'cloud [1-5] 'test. ping-vsalt 'test * 'test. ping-vsalt-e 'test. * 'test. ping-vsalt-l 'testvm01, testvm02 'test. ping-V # do not have spaces in the middle salt-G' OS: centos 'test. ping-V # Similarly, do not have extra characters Salt-N 'group1' test. ping-vsalt-s '192. 0.0.1 'test. ping-V # minion matches salt-c '[email protected] * and [email protected]: centos 'test. ping-V # Allow logical operations # In addition, it has not been applied for the time being. It will be left for future supplements ......
> Explanation of saltstack source code (0.17.5)
1. Salt-master end
Target code is scattered in/usr/lib/python2.6/Site-packages/salt/client/_ init __. PY (1151 behavior pub method), in fact, in the master side does not complete too many parsing tasks, just completed a simple job such as range Server Parsing. The principle of the push command is that the master uses the run_job method to uniformly publish a job. Then, this method uses zmq to publish pub. All minion will receive the data and complete subsequent work based on whether the data meets the requirements.
2. Salt-Minion end
The main matching work is completed here. The minion code is located in/usr/lib/python2.6/Site-packages/salt/minion. PY (the main code is the matcher class starting with line 1485, which further calls the comparison method of saltutil to confirm whether the matching is done). Here we will take a simple example to explain.
Def pcre_match (self, TGT): ''' returns true if the passed PCRE RegEx matches ''' # note that the re module is used for regular expression matching, the value # Is a Boolean value, which is similar to other methods, that is, whether the minion matches. Return bool (Re. Match (TGT, self. opts ['id'])
> Run the task in batches using the batch option.
Saltstack provides the-B option, which allows batch processing of all hosts selected by target. Only the specified quantity or percentage is pushed at a time until all the hosts are pushed. I personally think this is quite a weakness. It is best to customize it for batch running. It is better to use the python client of salt to write an auxiliary script. After all, this cannot be interrupted or grasped.
Salt '*'-B 10 test. Ping #10 at a time, batch push salt-G' OS: RedHat '-- batch-size 25% test. Ping # 25% at a time
Reference: salt Official Website
This article is from "Love blog" blog, please be sure to keep this source http://jackywu.blog.51cto.com/3011457/1434911