The final module

Once we have compiled all of the code together, the final module will look like this:

''' Store return data locally in JSON format This file should be saved as salt/returners/local_json.py ''' import json import os.path import salt.utils import salt.utils.find import salt.utils.jid import salt.syspaths def _job_path(jid): ''' Return the path for the requested JID ''' return os.path.join( salt.syspaths.CACHE_DIR, 'master', 'json_cache', jid[:4], jid[4:6], jid[6:], ) def returner(ret): ''' Open new file, and save return data to it in JSON format ''' path = os.path.join(_job_path(ret['jid']), ret['id']) + '/' __salt__['file.makedirs'](path) ret_file = os.path.join(path, 'return.json') with salt.utils.fopen(ret_file, 'w') as fp_: json.dump(ret, ...

Get Extending SaltStack now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.