Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable ansible verbosity only for failed tasks?

I am aware about ansible -vvv option but I don't want to see verbose output for all commands, I an interested in seeing details only if the task fails.

How can I achieve this?

PS. Please provide a solution that does scale, having to edit each task would not make any sense.

like image 804
sorin Avatar asked Feb 19 '16 15:02

sorin


1 Answers

I think there is only one way: You could edit the default callback plugin (or write your own callback plugin) which you will find here (by default)

site-packages/ansible/plugins/callback/default.py

See line 40 in

https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/callback/default.py

and just change the if condition accordingly. For Example replace lines 40-47 by:

msg = "An exception occurred during task execution. The full traceback is:\n" + result._result['exception']

self._display.display(msg, color=C.COLOR_ERROR)
like image 117
ProfHase85 Avatar answered Sep 30 '22 14:09

ProfHase85