Callbacks for shared Ansible traces?

I defined the callback as follows:

#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-

import sys
import pprint

from ansible.plugins.callback import CallbackBase


class JSONPrettyPrintCallback(CallbackBase):

    printer = pprint.PrettyPrinter(indent=4, stream=sys.stdout)

    def log(self, host, category, data):
        # one json blob to rule them all
        self.printer.pprint({'host': host, 'category': category, 'data': data})

In my Ansible config, I defined a path:

[defaults]
callback_plugins = callback_plugins/

However, when I run my module, I still see the default Ansible output:

10.0.0.1 | SUCCESS => {
    ...
}

I run it as follows:

ansible all -u myuser -m script -a 'path/to/script.py'

Do I need to do something to properly format my output?

0
source share
2 answers

If you want to replace the standard ANsible output, you must set stdout_callback for your callback.

Update: The stdout_callback parameter only affects CLI output ansible-playbook, as noted in the comments.

, ansible CLI minimal oneline ( -o ) stdout.
- ./callback_plugins/minimal.py . adhoc.py, stdout.

+5

, https://github.com/ansible/ansible/issues/16194 Ansible CLI ​​ https://github.com/ansible/ansible/pull/26098 stdout_callback.

, stdout_callback (ANSIBLE_STDOUT_CALLBACK env) bin_ansible_callbacks = Yes (ANSIBLE_LOAD_CALLBACK_PLUGINS env).

Ansible 2.2 2.3

+3

All Articles