Grains
Grains is a collection of information that is collected at Minion startup, such as the operating system type, network card IP, and so on. Using Commands
Salt ' client.aming.com ' grains.ls lists all grains project names
Salt ' client.aming.com ' grains.items lists all grains items and values
grains information is not dynamic and is not always changed, it is only collected at minion startup.
grains can do configuration management.
Custom Grains
vim/etc/salt/minion
Add or change:
Grains:
role:
-Nginx
env:
-Test
or
Vim/etc/salt/grains //client editor
Add:
Role:nginx
env:test
Restart Minion Service
Get Grains:
Salt ' * ' grains.item role env
Salt ' client.aming.com ' grains.get role
grains is actually very handy when executing commands remotely. We can follow some of the grains's indicators to operate. For example, the grains role of all Web servers is set to Nginx, so that we can batch to the Nginx server operation:
salt-g role:nginx cmd.run ' hostname '
Salt-g os:centos cmd.run ' hostname '
Saltstack--grains