Created
June 17, 2013 13:13
-
-
Save iMilnb/5796760 to your computer and use it in GitHub Desktop.
A simple SaltStack returner that prints state summary in a human-readable flat file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Return human readable salt data to a flat file | |
''' | |
# Import python libs | |
import yaml | |
def __virtual__(): | |
return 'file' | |
def returner(ret): | |
''' | |
Writes human readable output to a file | |
''' | |
retfile = __salt__['config.option']('file.return') | |
if not retfile: | |
retfile = '/tmp/file_return.txt' | |
out = {} | |
if isinstance(ret['return'], dict): | |
for state in ret['return'].keys(): | |
act = state.split('_|-') | |
out[act[1]] = {} | |
out[act[1]]['type'] = act[0] | |
for item in ['name', 'comment', 'result']: | |
out[act[1]][item] = ret['return'][state][item] | |
else: | |
out = ret['return'] | |
f = open(retfile, 'w') | |
f.write('id: {0}\nfunction: {1}\njid: {2}\n'.format( | |
ret['id'], ret['fun'], ret['jid'])) | |
f.write(yaml.dump(out, default_flow_style=False)) | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment