Saltstack Study Notes 4-grains

Source: Internet
Author: User
Tags saltstack

Grains is a component of Saltstack record Minion static information, we can simply understand that the grains contains some of the common properties of each minion, such as CPU, memory, disk, network information, etc. We can view a minion of all grains information through the Grains.items, Minions grains information is minions start when the collection report to master, in the actual application environment we need to customize some grains according to their business needs.


There are three ways of defining Minion:

Minion end through configuration file definition

Minion end through module definition

Python is defined by a template


Grains Simple Command usage

Salt ' minion1 ' sys.list_functions grains

Minion1:

-Grains.append

-Grains.delval

-Grains.filter_by

-Grains.get

-Grains.get_or_set_hash

-Grains.has_value

-Grains.item

-Grains.items

-Grains.ls

-Grains.remove

-Grains.setval

-Grains.setvals

Grains like the above method, detailed usage can be viewed by command

Salt ' minion1 ' sys.doc grains

-----------------------------------------------------------------------

Minion through the configuration file definition, this method is very simple to modify the Minion configuration file

Vim/etc/salt/minion, the comment section has a

#grains:

# roles:

#-Webserver

#-Memcache

# Deployment:datacenter4

# cabinet:13

# cab_u:14-15


For unified control grains can write information to a file

Grains can be modified and defined in this YAML format

/etc/salt/grains


Grains

Roles

-Webserver

-Memcache

Deployment:datacenter4

Cabinet:13

Cab_u:14-15

Restart Minion to make it effective

Salt ' minion1 ' Grains.item grains:roles

Minion1:

----------

Grains:roles:

-Webserver

-Memcache

--------------------------------------------------------------------------------

Defined by the Grains module grains


Salt ' minion1 ' grains.append saltbook ' Verycool '

Minion1:

----------

Saltbook:

-Verycool

[email protected] apache]# Salt ' minion1 ' Grains.item saltbook

Minion1:

----------

Saltbook:

-Verycool


You can use Grains.setvals to set multiple grains information at the same time

Salt ' minion1 ' grains.setvals ' {' Salt ': ' Good ', ' book ': ' Cool '} '

Minion1:

----------

Book

Cool

Salt

Good

[[email protected] apache]# Salt ' minion1 ' grains.item salt

Minion1:

----------

Salt

Good

[[email protected] apache]# Salt ' minion1 ' Grains.item book

Minion1:

----------

Book

Cool

Of course, the deletion of grains information is also supported, and more usage can be queried by Sys.doc grains command

----------------------------------------------------------------------------

Adding grains methods using Python scripting we'll talk about it later.

This article from "Eight Miles" blog, declined reprint!

Saltstack Study Notes 4-grains

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.