sorin
sorin

Reputation: 170390

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.

Upvotes: 6

Views: 1440

Answers (1)

ProfHase85
ProfHase85

Reputation: 12173

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)

Upvotes: 2

Related Questions