suppress summary from salt-call but show warnings and errors

33 views Asked by At

I am trying to suppress all output from salt-call/salt state.apply unless there is an error or warning of any kind; no output means no summary, either.

No combination of --state-verbose or --state-output silences the summary.

Adding --out=quiet gets rid of the summary but also warnings and errors, providing only a return code.

For now, I am handling it this way:

salt-call state.apply <my_state> --state_output=mixed --state_verbose=false --out-file=/tmp/state-out-tmp-$$.txt
(($?)) && cat /tmp/state-out-tmp-$$.txt
rm /tmp/state-out-tmp-$$.txt

... but this seems to be overkill.

Is there some combination of options I am missing?

1

There are 1 answers

0
OrangeDog On

The simple way is to output json and pipe it through an additional parsing step:

salt-call state.apply <my_state> --out=json | jq '.local[] | select(.result == false)'

A cleaner way is to implement your own outputter that returns exactly what you want to see:

import json

def output(data, **kwargs):
    failing = {host: {state: ret["comment"] for state, ret in r.items() 
                      if ret["result"] is False} 
               for host, r in data.items()}
    return json.dumps(failing, indent=4)

Note that errors and warnings should also be logged, so you could simply go for:

salt-call state.apply <my_state> --out=quiet --log-level=warning