Skip to content

Commit

Permalink
ignore version when deciding callback loading (#38281)
Browse files Browse the repository at this point in the history
* ignore version when deciding callback loading

The code already defaulted to load the callback if the properties are not present
there was no need for us to also check the version

fixes #38270

* fix error msg on set optoins to use correct name

(cherry picked from commit 1850bb7)
  • Loading branch information
bcoca committed Apr 30, 2018
1 parent 8048609 commit 19ab7b4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/cb_ignore.yml
@@ -0,0 +1,2 @@
bugfixes:
- dont require property for older callbacks to load https://github.com/ansible/ansible/pull/38281
31 changes: 15 additions & 16 deletions lib/ansible/executor/task_queue_manager.py
Expand Up @@ -188,30 +188,29 @@ def load_callbacks(self):
raise AnsibleError("callback must be an instance of CallbackBase or the name of a callback plugin")

for callback_plugin in callback_loader.all(class_only=True):
if hasattr(callback_plugin, 'CALLBACK_VERSION') and callback_plugin.CALLBACK_VERSION >= 2.0:
# we only allow one callback of type 'stdout' to be loaded, so check
# the name of the current plugin and type to see if we need to skip
# loading this callback plugin
callback_type = getattr(callback_plugin, 'CALLBACK_TYPE', None)
callback_needs_whitelist = getattr(callback_plugin, 'CALLBACK_NEEDS_WHITELIST', False)
(callback_name, _) = os.path.splitext(os.path.basename(callback_plugin._original_path))
if callback_type == 'stdout':
if callback_name != self._stdout_callback or stdout_callback_loaded:
continue
stdout_callback_loaded = True
elif callback_name == 'tree' and self._run_tree:
pass
elif not self._run_additional_callbacks or (callback_needs_whitelist and (
C.DEFAULT_CALLBACK_WHITELIST is None or callback_name not in C.DEFAULT_CALLBACK_WHITELIST)):
callback_type = getattr(callback_plugin, 'CALLBACK_TYPE', '')
callback_needs_whitelist = getattr(callback_plugin, 'CALLBACK_NEEDS_WHITELIST', False)
(callback_name, _) = os.path.splitext(os.path.basename(callback_plugin._original_path))
if callback_type == 'stdout':
# we only allow one callback of type 'stdout' to be loaded,
if callback_name != self._stdout_callback or stdout_callback_loaded:
continue
stdout_callback_loaded = True
elif callback_name == 'tree' and self._run_tree:
# special case for ansible cli option
pass
elif not self._run_additional_callbacks or (callback_needs_whitelist and (
C.DEFAULT_CALLBACK_WHITELIST is None or callback_name not in C.DEFAULT_CALLBACK_WHITELIST)):
# 2.x plugins shipped with ansible should require whitelisting, older or non shipped should load automatically
continue

callback_obj = callback_plugin()
try:
callback_obj.set_options()
except AttributeError:
display.deprecated("%s callback, does not support setting 'options', it will work for now, "
" but this will be required in the future and should be updated, "
" see the 2.4 porting guide for details." % self._stdout_callback._load_name, version="2.9")
" see the 2.4 porting guide for details." % self.callback_obj._load_name, version="2.9")
self._callback_plugins.append(callback_obj)

self._callbacks_loaded = True
Expand Down

0 comments on commit 19ab7b4

Please sign in to comment.