Petr
Petr

Reputation: 14485

How can I make Ansible show only errors in execution?

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).

Upvotes: 6

Views: 7176

Answers (2)

hamletmun
hamletmun

Reputation: 71

You could run the command with actionable callback

ANSIBLE_STDOUT_CALLBACK=actionable ansible all -a 'some_command_I_want_to_know_if_it_crashes'

Upvotes: 0

techraf
techraf

Reputation: 68489

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.

Upvotes: 3

Related Questions