本人水平有限,也是在网上参考的 [root@salt-master _grains]# tree /srv/salt/ /srv/salt/ ├── base │ ├── 1.txt │ ├── _grains │ │ ├── grains_openfile.py │ │ └── server_time.py //我的目录下新增了这个python脚本 │ └── test └── prod └── 5.txt
[root@salt-master _grains]# vim server_time.py #!/usr/bin/env python # coding=utf-8 from datetime import datetime def get_server_time(): grains = {} grains['server_time'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S') return grains [root@salt-master _grains]# salt '*' saltutil.sync_all salt-master: ---------- beacons: engines: grains: - grains.server_time log_handlers: modules: output: proxymodules: renderers: returners: sdb: states: utils: salt-minion01: ---------- beacons: engines: grains: - grains.server_time log_handlers: modules: output: proxymodules: renderers: returners: sdb: states: utils: hddcluster2: ---------- beacons: engines: grains: - grains.server_time log_handlers: modules: output: proxymodules: renderers: returners: sdb: states: utils: hddcluster4: ---------- beacons: engines: grains: - grains.server_time log_handlers: modules: output: proxymodules: renderers: returners: sdb: states: utils: hddcluster3: ---------- beacons: engines: grains: - grains.server_time log_handlers: modules: output: proxymodules: renderers: returners: sdb: states: utils: hddcluster1: ---------- beacons: engines: grains: - grains.server_time log_handlers: modules: output: proxymodules: renderers: returners: sdb: states: utils: [root@salt-master _grains]# salt '*' sys.reload_modules salt-minion01: True salt-master: True hddcluster2: True hddcluster4: True hddcluster3: True hddcluster1: True [root@salt-master _grains]# salt '*' grains.item server_time salt-master: ---------- server_time: 2016-12-01 17:27:14 salt-minion01: ---------- server_time: 2016-12-01 17:27:14 hddcluster2: ---------- server_time: 2016-12-01 17:27:14 hddcluster3: ---------- server_time: 2016-12-01 17:27:25 hddcluster4: ---------- server_time: 2016-12-01 17:27:25 hddcluster1: ---------- server_time: 2016-12-01 17:27:25 [root@salt-master _grains]#
转载于:https://blog.51cto.com/yanconggod/1878598