本文共 2494 字,大约阅读时间需要 8 分钟。
本人水平有限,也是在网上参考的[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-8from datetime import datetimedef 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: Truesalt-master: Truehddcluster2: Truehddcluster4: Truehddcluster3: Truehddcluster1: True[root@salt-master _grains]# salt '*' grains.item server_timesalt-master: ---------- server_time: 2016-12-01 17:27:14salt-minion01: ---------- server_time: 2016-12-01 17:27:14hddcluster2: ---------- server_time: 2016-12-01 17:27:14hddcluster3: ---------- server_time: 2016-12-01 17:27:25hddcluster4: ---------- server_time: 2016-12-01 17:27:25hddcluster1: ---------- server_time: 2016-12-01 17:27:25[root@salt-master _grains]#
转载于:https://blog.51cto.com/yanconggod/1878598