Grains #收集设备的所有信息
Grains is a collection of information that is collected at Minion startup, such as the operating system type, network card IP, kernel version, CPU architecture, and so on.
Using commands
Salt ' client.wyp.com ' grains.ls lists all grains project names
Salt ' client.wyp.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.
We can do configuration management according to some information collected by grains.
Grains supports custom information.
Custom Grains
On the client:
Vim/etc/salt/minion
Add or change:
Grains
Role
-Nginx
Env:
-Test
Or
Vim/etc/salt/grains
Add to:
Role:nginx #注意空格, preceded by a custom name, followed by a value.
Env:test
Restart Minion Service
To get grains on the server:
Salt ' * ' grains.item role env
Salt ' client.wyp.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 '
2.3-saltstack Grains