From 64cbb71e6e5fb1972c0809036979ab578537f791 Mon Sep 17 00:00:00 2001 From: simonLeary42 <71396965+simonLeary42@users.noreply.github.com> Date: Wed, 8 Jan 2025 11:26:42 -0500 Subject: FIX get_options function for CallbackBase (#84496) --- changelogs/fragments/84496-CallbackBase-get_options.yml | 4 ++++ lib/ansible/plugins/__init__.py | 2 +- lib/ansible/plugins/callback/__init__.py | 5 ++++- 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/84496-CallbackBase-get_options.yml diff --git a/changelogs/fragments/84496-CallbackBase-get_options.yml b/changelogs/fragments/84496-CallbackBase-get_options.yml new file mode 100644 index 0000000000..09bcd4bb6d --- /dev/null +++ b/changelogs/fragments/84496-CallbackBase-get_options.yml @@ -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 diff --git a/lib/ansible/plugins/__init__.py b/lib/ansible/plugins/__init__.py index ff9068effa..44112597aa 100644 --- a/lib/ansible/plugins/__init__.py +++ b/lib/ansible/plugins/__init__.py @@ -129,7 +129,7 @@ class AnsiblePlugin(ABC): @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 diff --git a/lib/ansible/plugins/callback/__init__.py b/lib/ansible/plugins/callback/__init__.py index aa75ac5fa3..12d97a5a96 100644 --- a/lib/ansible/plugins/callback/__init__.py +++ b/lib/ansible/plugins/callback/__init__.py @@ -171,9 +171,12 @@ class CallbackBase(AnsiblePlugin): 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. -- cgit v1.2.3