The grain interface is some information about the underlying system,it is available for all the Salt module and compounts
salt 'host' grains.ls # to list all the grains in the salt minion of the host
salt "host" grains.items # to show all the items in the salt minion whose host is host
salt "host" grains.item os (or certain item) # to show the certain items in the salt minion
self-define grains in salt minions
edit /etc/salt/grains ,the contents like following:
roles:
- webserver
- memcache
deployment: datacenter4
cabinet: 13
cab_u: 14-15
restart salt-minion and run salt 'host' grains.ls ,you will find the new grain u add
notice the blank between the key and value of "cab_u: 14-15"
use grains in command lines like following:
salt -G 'os:CentOS' test.ping #matching all the Centos minions
salt -C 'G@circle:live and G@data_volume_attached:True' #use grains matching in compound matching
use grains in top.sls files:
'node_type:web':
- match: grain
- webserver
'node_type:postgres':
- match: grain
- database
'node_type:redis':
- match: grain
- redis
'node_type:lb':
- match: grain
- lb