Callbacks for generic Ansible runs?

前端 未结 2 412
后悔当初
后悔当初 2020-12-20 04:40

I have defined a callback like so:

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

import sys
import pprint

from ansible.plugins.callback import CallbackB         


        
相关标签:
2条回答
  • 2020-12-20 05:14

    If you want to replace Ansible standard output, you should set stdout_callback parameter to your callback.

    Update: stdout_callback parameter will affect only ansible-playbook CLI output, as correctly noted in the comments.

    I've investigated the code a bit, ansible CLI supports only minimal and oneline (if -o option is set) stdout callbacks.
    The easiest way to change the output behavior is to place ./callback_plugins/minimal.py in your playbook folder and modify it to your needs.
    Or you can patch adhoc.py to be able to accept other stdout plugins.

    0 讨论(0)
  • 2020-12-20 05:32

    There was a bug reported https://github.com/ansible/ansible/issues/16194 and Ansible CLI was just fixed in https://github.com/ansible/ansible/pull/26098 to respect custom stdout_callback.

    To have custom callbacks working you need to specify both stdout_callback (ANSIBLE_STDOUT_CALLBACK env) and bin_ansible_callbacks = Yes (ANSIBLE_LOAD_CALLBACK_PLUGINS env).

    The change should be backported to both Ansible 2.2 and 2.3

    0 讨论(0)
提交回复
热议问题