Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions salt/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
'random_master': bool,
'syndic_event_forward_timeout': float,
'syndic_max_event_process_time': float,
'salt_fails_if_highstate_fails': bool,
}

# default configurations
Expand Down Expand Up @@ -401,6 +402,7 @@
'gather_job_timeout': 2,
'syndic_event_forward_timeout': 0.5,
'syndic_max_event_process_time': 0.5,
'salt_fails_if_highstate_fails': False
}

# ----- Salt Cloud Configuration Defaults ----------------------------------->
Expand Down
13 changes: 13 additions & 0 deletions salt/output/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import salt.loader
import salt.utils

from salt.exceptions import SaltSystemExit


log = logging.getLogger(__name__)

Expand All @@ -39,6 +41,7 @@ def display_output(data, out, opts=None):
display_data = get_printout('nested', opts)(data).rstrip()

output_filename = opts.get('output_file', None)
salt_fails_if_highstate_fails = opts.get('salt_fails_if_highstate_fails', False)
try:
if output_filename is not None:
with salt.utils.fopen(output_filename, 'a') as ofh:
Expand All @@ -47,11 +50,21 @@ def display_output(data, out, opts=None):
return
if display_data:
print(display_data)
if salt_fails_if_highstate_fails:
if not get_highstate_success(highstate_data=data):
raise SaltSystemExit(code=1)

except IOError as exc:
# Only raise if it's NOT a broken pipe
if exc.errno != errno.EPIPE:
raise exc

def get_highstate_success(highstate_data):
for i in highstate_data.keys():
for j in highstate_data[i].keys():
if not highstate_data[i][j]['result']:
return False
return True

def get_printout(out, opts=None, **kwargs):
'''
Expand Down