Saltstack Grains Components (5)

Source: Internet
Author: User
Tags saltstack

Grains is the most important component of saltstack, the role of grains is the basic information of the mobile phone is controlled by the host, these information are static data, such as CPU, kernel, operating system, virtualization, etc., on the server side can be flexibly customized according to this information, This information can be used by administrators to personalize different businesses (the first class is understood as: grains is used to differentiate between different minion for different configurations, salt ' * ', mainly in the ' * ' to match the role of the host)


1, Grains Common Operation command

Match kernel version 2.6.32-358.14.1.el6.x86_64 to minion and execute command ' uname-a '

Salt-g ' kernelrelease:2.6.32-358.14.1.el6.x86_64 ' cmd.run ' uname-a '

Get grains information for all minion

Salt ' * ' grains.ls

Of course, you can also get host item grains data, such as get Operation release version,

Salt ' sn2013-08-022 ' Grains.item os


2. Define Grains Data

There are two ways to define grains data, one of which is the Minion custom profile and the other through the Master Extension Module API, which is more flexible and can be dynamically defined with Python programming, whereas a configuration file is only suitable for a relative fixed key and value. The following examples illustrate

(1) Minion custom static grains data

SSH login minion, configuration file customization path is/etc/salt/minion, parameter is default_include:minion.d/*conf, open the secondary option # #注意前面留空格

Create file "/etc/salt/minion.d/hostinfo.conf"


Grains

Roles

-Webserver

-Memcache

Deployment:datacenter4

Cabinet:14

Restart the Minion service, verify that the results run on master: Salt ' sn2013-08-022 ' grains.item roles deployment cabinet, observe the configured key and value

(2) Master expansion module custom grains data

First write the Python code in master, then synchronize the Python file to Minion, and finally the refresh takes effect (that is, compiling the Python source code file into bytecode PYc). In the main terminal base directory (see the File_roots entry for the/etc/salt/master configuration file, the default base configuration is/srv/salt) to generate the _grains directory, execute install-d/srv/salt/_ Grains Start writing code

 
  • Grains_openfile () defines a function that gets the maximum number of open files, the function name is not required, and it conforms to the Python function naming convention.

  • grains={} Initializes a grains dictionary, and the variable name must be grainsin order to saltstack identify

  • grains[' Max_open_file ']=_open_file assigns the resulting value of the acquired Linux ulimit-n to grains[' Max_open_file ', where "max_open_file" is the grains item, _ Open_file is the value of grains.

In the main terminal synchronization module:salt ' sn2013-08-022 ' saltutil.sync_grains or salt 'sn2013-08-022' Saltutil.sync_all, At this point the file is synchronized to the following directory of the host console, as follows:

/var/cache/salt/minion/extmods/grains/grains_openfile.py and GRAINS_OPENFILE.PYC

/var/cache/salt/minion/files/base/_grains/grains_openfile.py

/var/cache/salt/minion/extmods/grains/for the Extension module file final storage location, refresh the module will be generated under the same path byte code PYC;

/var/cache/salt/minion/files/base/_grains/for temporary storage location

Perform a checksum on the master side to execute the salt ' sn2013-08-022 ' grains.item max_open_file


Saltstack Grains Components (5)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.