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