salt -E 'angel01' grains.ls #查看有多少定义好的属性可以用
salt -E 'angel01' grains.items #查看所有属性返回的值
salt -E 'angel01' grains.item fqdn os #查看fqdn os 返回的值,以此类推
grains自定义
服务端主动推送
master上操作
12345678910111213141516171819202122232425
vim /mnt/config/salt/master
增加默认目录
file_roots:
base:
- /mnt/config/salt/
mkdir -p /mnt/config/salt/_grains/
vim /mnt/config/salt/_grains/test.py
# -*- coding: utf-8 -*-
'''
leon test
'''
import commands
import os
def l_test():
'''
leon test
'''
grains={}
a = commands.getoutput("hostname")
grains['leon_test']=a
return grains
[root@angel01 salt]# salt '*' sys.reload_modules
angel01.i.fdmdns.com:
True
angel02.i.fdmdns.com:
True
[root@angel01 salt]# salt '*' saltutil.sync_all
angel01.i.fdmdns.com:
----------
grains:
- grains.test
modules:
outputters:
renderers:
returners:
states:
angel02.i.fdmdns.com:
----------
grains:
- grains.test
modules:
outputters:
renderers:
returners:
states:
[root@angel01 salt]# salt '*' grains.item leon_test
angel01.i.fdmdns.com:
leon_test: this is test
angel02.i.fdmdns.com:
leon_test: this is test
客户端自动汇报
minion上操作
123456789101112131415161718192021222324252627
vim /etc/salt/minion
default_include: /mnt/config/salt/minion.d/*.conf #增加这项
mkdir -p /mnt/config/salt/minion.d/
vim /mnt/config/salt/minion.d/test.conf
grains:
leon and leon: 1
leon and alex: print 2
cpis:
- a
- b
leon.com:
-------------------------------------------------
/etc/init.d/salt-minion restart
[root@angel01 ~]# salt -E 'angel01' grains.item leon\ and\ leon
angel01.i.fdmdns.com:
leon and leon: 1
[root@angel01 ~]# salt -E 'angel01' grains.item leon.com
angel01.i.fdmdns.com:
leon.com: -------------------------------------------------
[root@angel01 ~]# salt -E 'angel01' grains.item cpis
angel01.i.fdmdns.com:
cpis:
a
b