Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make Ansible show only errors in execution?

Tags:

ansible

How can I make ansible show only errors inside of some playbook, or even when directly invoked?

I tried suppressing std output but that apparently didn't help, because execution errors seem to be put into standard output instead of error output on Linux.

ansible all -a 'some_command_I_want_to_know_if_it_crashes' 1> /dev/null

I see only errors from Python (exceptions etc.) but not errors from playbook (the red text).

like image 687
Petr Avatar asked Oct 25 '16 11:10

Petr


1 Answers

Use the official sample callback plugin called actionable.py.

Put it in the callback_plugins directory and enable stdout-callbacks in ansible.cfg:

[defaults]
stdout_callback = actionable

Just by enabling it you will get much less information in th output, but you can further modify the plugin code to suit your needs.

For example to disable messages on successful tasks completely (regardless if status is ok or changed) change:

def v2_runner_on_ok(self, result):
    if result._result.get('changed', False):
        self.display_task_banner()
        self.super_ref.v2_runner_on_ok(result)

to

def v2_runner_on_ok(self, result):
    pass

As Konstantin Suvorov noted, the above ansible.cfg configuration method works for ansible-playbook.

For ansible output you can save the actionable.py as ./callback_plugins/minimal.py to achieve the same results.

like image 96
techraf Avatar answered Oct 18 '22 13:10

techraf