Random   •   Archives   •   RSS   •   About   •   Contact

Filter Salt Stack Return Data Output

Sometimes you only want to see what has changed, and that is OK.

Create a file like this:

filter.py

#!/usr/bin/python

from json import loads
from json import dumps

import fileinput

stdin_lines = [line for line in fileinput.input()]

ret = loads(''.join(stdin_lines))

for minion_id, data in ret.items():
    print(minion_id)
    print('='*len(minion_id))
    for key, value in ret[minion_id].items():
        if value['changes'] or value['result'] == False:
            print('')
            print(dumps(value, indent=4))
            print('')

Make the file executable:

chmod 755 filter.py

Execute your remote execution like this:

sudo salt-call --out=json state.highstate | ./filter.py

sudo salt '*' --out=json  --timeout=60 --static state.highstate | ./filter.py

The flags --timeout=60 and --static will cause the Salt command to block until the specified seconds for each minion to return results. We then pipe the returned JSON into our filter.py script to filter out only the changes and failures!

Profit!

Change the conditional depending on what you want. For example, for just failures do this:

if value['result'] == False:

Example output:

# sudo salt 'graphite.foxhop.net' --out=json --static --timeout=60 state.highstate | ./filter.py

graphite.foxhop.net
===================

{
    "comment": "File /tmp/taco updated",
    "__run_num__": 15,
    "changes": {
        "diff": "New file",
        "mode": "0640"
    },
    "name": "/tmp/taco",
    "result": true
}




Looking for a better comment system?

You should try Remarkbox — a hosted comment service that embeds in your pages to keep the conversation in the same place as your content. It works everywhere, even static sites!

Remarks: Filter Salt Stack Return Data Output

© Russell Ballestrini.