Skip to content

Commit

Permalink
FIX get_options function for CallbackBase (ansible#84496)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonLeary42 authored Jan 8, 2025
1 parent ed250ec commit 64cbb71
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions changelogs/fragments/84496-CallbackBase-get_options.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
minor_changes:
- callback plugins - add has_option() to CallbackBase to match other functions overloaded from AnsiblePlugin
- callback plugins - fix get_options() for CallbackBase
2 changes: 1 addition & 1 deletion lib/ansible/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def plugin_type(self):

@property
def option_definitions(self):
if self._defs is None:
if (not hasattr(self, "_defs")) or self._defs is None:
self._defs = C.config.get_configuration_definitions(plugin_type=self.plugin_type, name=self._load_name)
return self._defs

Expand Down
5 changes: 4 additions & 1 deletion lib/ansible/plugins/callback/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,12 @@ def __init__(self, display=None, options=None):
def set_option(self, k, v):
self._plugin_options[k] = C.config.get_config_value(k, plugin_type=self.plugin_type, plugin_name=self._load_name, direct={k: v})

def get_option(self, k):
def get_option(self, k, hostvars=None):
return self._plugin_options[k]

def has_option(self, option):
return (option in self._plugin_options)

def set_options(self, task_keys=None, var_options=None, direct=None):
""" This is different than the normal plugin method as callbacks get called early and really don't accept keywords.
Also _options was already taken for CLI args and callbacks use _plugin_options instead.
Expand Down

0 comments on commit 64cbb71

Please sign in to comment.