mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 21:32:49 +00:00
Merge pull request #3827 from mscherer/disable_callbacks
add a way for callback to disable itself
This commit is contained in:
@@ -21,11 +21,16 @@ class CallbackModule(object):
|
||||
"""
|
||||
this is an example ansible callback file that does nothing. You can drop
|
||||
other classes in the same directory to define your own handlers. Methods
|
||||
you do not use can be omitted.
|
||||
you do not use can be omitted. If self.disabled is set to True, the plugin
|
||||
methods will not be called.
|
||||
|
||||
example uses include: logging, emailing, storing info, etc
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
#if foo:
|
||||
# self.disabled = True
|
||||
pass
|
||||
|
||||
def on_any(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
@@ -144,6 +144,10 @@ def display(msg, color=None, stderr=False, screen_only=False, log_only=False, ru
|
||||
def call_callback_module(method_name, *args, **kwargs):
|
||||
|
||||
for callback_plugin in callback_plugins:
|
||||
# a plugin that set self.disabled to True will not be called
|
||||
# see osx_say.py example for such a plugin
|
||||
if getattr(callback_plugin, 'disabled', False):
|
||||
continue
|
||||
methods = [
|
||||
getattr(callback_plugin, method_name, None),
|
||||
getattr(callback_plugin, 'on_any', None)
|
||||
|
||||
Reference in New Issue
Block a user