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:



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():
    for key, value in ret[minion_id].items():
        if value['changes'] or value['result'] == False:
            print(dumps(value, indent=4))

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!


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


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

© Russell Ballestrini.