@ -21,15 +21,14 @@ DOCUMENTATION = '''
'''
'''
from os . path import basename
from os . path import basename
from ansible import constants as C
from ansible import constants as C
from ansible import context
from ansible import context
from ansible . module_utils . _text import to_text
from ansible . module_utils . _text import to_text
from ansible . plugins . callback import CallbackBase
from ansible . utils . color import colorize , hostcolor
from ansible . utils . color import colorize , hostcolor
from ansible . plugins . callback . default import CallbackModule as CallbackModule_default
class CallbackModule ( Callback Base ) :
class CallbackModule ( Callback Module_default ) :
'''
'''
Design goals :
Design goals :
@ -48,6 +47,9 @@ class CallbackModule(CallbackBase):
CALLBACK_TYPE = ' stdout '
CALLBACK_TYPE = ' stdout '
CALLBACK_NAME = ' unixy '
CALLBACK_NAME = ' unixy '
def _run_is_verbose ( self , result ) :
return ( ( self . _display . verbosity > 0 or ' _ansible_verbose_always ' in result . _result ) and ' _ansible_verbose_override ' not in result . _result )
def _get_task_display_name ( self , task ) :
def _get_task_display_name ( self , task ) :
self . task_display_name = None
self . task_display_name = None
display_name = task . get_name ( ) . strip ( ) . split ( " : " )
display_name = task . get_name ( ) . strip ( ) . split ( " : " )
@ -60,7 +62,7 @@ class CallbackModule(CallbackBase):
def _preprocess_result ( self , result ) :
def _preprocess_result ( self , result ) :
self . delegated_vars = result . _result . get ( ' _ansible_delegated_vars ' , None )
self . delegated_vars = result . _result . get ( ' _ansible_delegated_vars ' , None )
self . _handle_exception ( result . _result )
self . _handle_exception ( result . _result , use_stderr = self . display_failed_stderr )
self . _handle_warnings ( result . _result )
self . _handle_warnings ( result . _result )
def _process_result_output ( self , result , msg ) :
def _process_result_output ( self , result , msg ) :
@ -106,12 +108,15 @@ class CallbackModule(CallbackBase):
self . _display . display ( msg )
self . _display . display ( msg )
def v2_runner_on_skipped ( self , result , ignore_errors = False ) :
def v2_runner_on_skipped ( self , result , ignore_errors = False ) :
self . _preprocess_result ( result )
if self . display_skipped_hosts :
display_color = C . COLOR_SKIP
self . _preprocess_result ( result )
msg = " skipped "
display_color = C . COLOR_SKIP
msg = " skipped "
task_result = self . _process_result_output ( result , msg )
task_result = self . _process_result_output ( result , msg )
self . _display . display ( " " + task_result , display_color )
self . _display . display ( " " + task_result , display_color )
else :
return
def v2_runner_on_failed ( self , result , ignore_errors = False ) :
def v2_runner_on_failed ( self , result , ignore_errors = False ) :
self . _preprocess_result ( result )
self . _preprocess_result ( result )
@ -119,7 +124,7 @@ class CallbackModule(CallbackBase):
msg = " failed "
msg = " failed "
task_result = self . _process_result_output ( result , msg )
task_result = self . _process_result_output ( result , msg )
self . _display . display ( " " + task_result , display_color )
self . _display . display ( " " + task_result , display_color , stderr = self . display_failed_stderr )
def v2_runner_on_ok ( self , result , msg = " ok " , display_color = C . COLOR_OK ) :
def v2_runner_on_ok ( self , result , msg = " ok " , display_color = C . COLOR_OK ) :
self . _preprocess_result ( result )
self . _preprocess_result ( result )
@ -128,9 +133,11 @@ class CallbackModule(CallbackBase):
if result_was_changed :
if result_was_changed :
msg = " done "
msg = " done "
display_color = C . COLOR_CHANGED
display_color = C . COLOR_CHANGED
task_result = self . _process_result_output ( result , msg )
task_result = self . _process_result_output ( result , msg )
self . _display . display ( " " + task_result , display_color )
self . _display . display ( " " + task_result , display_color )
elif self . display_ok_hosts :
task_result = self . _process_result_output ( result , msg )
self . _display . display ( " " + task_result , display_color )
def v2_runner_item_on_skipped ( self , result ) :
def v2_runner_item_on_skipped ( self , result ) :
self . v2_runner_on_skipped ( result )
self . v2_runner_on_skipped ( result )
@ -146,7 +153,7 @@ class CallbackModule(CallbackBase):
display_color = C . COLOR_UNREACHABLE
display_color = C . COLOR_UNREACHABLE
task_result = self . _process_result_output ( result , msg )
task_result = self . _process_result_output ( result , msg )
self . _display . display ( " " + task_result , display_color )
self . _display . display ( " " + task_result , display_color , stderr = self . display_failed_stderr )
def v2_on_file_diff ( self , result ) :
def v2_on_file_diff ( self , result ) :
if result . _task . loop and ' results ' in result . _result :
if result . _task . loop and ' results ' in result . _result :
@ -189,6 +196,20 @@ class CallbackModule(CallbackBase):
colorize ( u ' ignored ' , t [ ' ignored ' ] , None ) ) ,
colorize ( u ' ignored ' , t [ ' ignored ' ] , None ) ) ,
log_only = True
log_only = True
)
)
if stats . custom and self . show_custom_stats :
self . _display . banner ( " CUSTOM STATS: " )
# per host
# TODO: come up with 'pretty format'
for k in sorted ( stats . custom . keys ( ) ) :
if k == ' _run ' :
continue
self . _display . display ( ' \t %s : %s ' % ( k , self . _dump_results ( stats . custom [ k ] , indent = 1 ) . replace ( ' \n ' , ' ' ) ) )
# print per run custom stats
if ' _run ' in stats . custom :
self . _display . display ( " " , screen_only = True )
self . _display . display ( ' \t RUN: %s ' % self . _dump_results ( stats . custom [ ' _run ' ] , indent = 1 ) . replace ( ' \n ' , ' ' ) )
self . _display . display ( " " , screen_only = True )
def v2_playbook_on_no_hosts_matched ( self ) :
def v2_playbook_on_no_hosts_matched ( self ) :
self . _display . display ( " No hosts found! " , color = C . COLOR_DEBUG )
self . _display . display ( " No hosts found! " , color = C . COLOR_DEBUG )