在客户端的minion里面写自定义的grains
客户端:
vim /etc/salt/minion
grains:
roles: nginx
env: prod
[root@node120 salt]# /etc/init.d/salt-minion restart
或者直接在/etc/salt目录下创建grains文件:
[root@node120 salt]# cat /etc/salt/grains
cloud: openstack
[root@node120 salt]# /etc/init.d/salt-minion restart
[root@node110 salt]# salt -G 'cloud:openstack' test.ping
minion.saltstack.com:
True
服务端:
[root@node110 salt]# salt 'minion.saltstack.com'grains.get env
minion.saltstack.com:
prod
[root@node110 salt]# salt 'minion.saltstack.com'grains.get roles
minion.saltstack.com:
nginx
[root@node110 salt]# salt -G 'env:prod' test.ping
minion.saltstack.com:
True
[root@node110 salt]# salt -G 'roles:nginx' test.ping
minion.saltstack.com:
True
刷新grains:
可以不用重启客户端minion而使用grains的配置文件生效:
[root@node110 salt]# salt -G 'test:salt' test.ping
No minions matched the target. No command was sent, nojid was assigned.
ERROR: No return received
[root@node110 salt]# salt '*' saltutil.sync_grains
minion.saltstack.com:
minion.node2.saltstack.com:
[root@node110 salt]# salt -G 'test:salt' test.ping
minion.saltstack.com:
True