Skip to content

Instantly share code, notes, and snippets.

@iMilnb
Created June 17, 2013 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iMilnb/5796760 to your computer and use it in GitHub Desktop.
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
'''
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