return 是在 minion 端运行的一个回调
创建return目录
1 2 mkdir /srv/salt/_returners
创建一个local_return /srv/salt/_returners/local_return.py
实现
1 2 3 4 5 6 7 8 9 10 11 12 13 #coding=utf8 import json def __virtual__(): return 'local_return' def returner(ret): ''' Return data to the local file ''' result_file = '/var/local/salt/returner' result = file(result_file,'a+') result.write(str(json.dumps(ret.values()))[1:-1]+'\n') result.close()
virtual () 用来定义返回器的名称
returner(ret) 为具体返回器执行的值
同步 1 2 sudo salt '*' saltutil.sync_all
执行 minion 端在执行完 test.ping 后会回调 local_runturn
1 2 sudo salt '*’ test.ping --return local_return
return reids 示例 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 try: import redis HAS_REDIS = True except ImportError: HAS_REDIS = False __virtualname__ = 'redis' def __virtual__(): if not HAS_REDIS: return False return __virtualname__ def returner(ret): ''' Return information to a redis server ''' # Get a redis connection serv = redis.Redis( host='redis-serv.example.com', port=6379, db='0') serv.sadd("%(id)s:jobs" % ret, ret['jid']) serv.set("%(jid)s:%(id)s" % ret, json.dumps(ret['return'])) serv.sadd('jobs', ret['jid']) serv.sadd(ret['jid'], ret['id'])