summaryrefslogtreecommitdiff
path: root/lib/ansible/plugins/__init__.py
diff options
context:
space:
mode:
authorBrian Coca <bcoca@users.noreply.github.com>2022-09-01 14:16:05 -0400
committerGitHub <noreply@github.com>2022-09-01 14:16:05 -0400
commit4260b71cc77b7a44e061668d0d408d847f550156 (patch)
treefa2bcbbacdcd3937a6aceeeefea704679909e340 /lib/ansible/plugins/__init__.py
parent2464e1e91c0ee1c65ecff450de973c3ce2ed767d (diff)
downloadansible-4260b71cc77b7a44e061668d0d408d847f550156.tar.gz
refactor and fixes for doc parsing (#77719)
* refactor and remove redundant code in documentation allow location and building api to be more accessible fix issues with displaying ansible.legacy and ansible.builtin ensure we don't x2 process tokens (some modules reference them also) fixes #77764 move to constants vs hardcoded more informative errors and comments now have actual filter/test plugins, which expose the filter/test functions moved filter/test loading/finding logic into jinja2pluginloader, removed dupe implementations added tests for case in which we unique by basename when listing Update lib/ansible/utils/plugin_docs.py Co-authored-by: Sloane Hertel <19572925+s-hertel@users.noreply.github.com>
Diffstat (limited to 'lib/ansible/plugins/__init__.py')
-rw-r--r--lib/ansible/plugins/__init__.py39
1 files changed, 35 insertions, 4 deletions
diff --git a/lib/ansible/plugins/__init__.py b/lib/ansible/plugins/__init__.py
index d3f8630f76..8bc855a6e2 100644
--- a/lib/ansible/plugins/__init__.py
+++ b/lib/ansible/plugins/__init__.py
@@ -57,11 +57,12 @@ class AnsiblePlugin(ABC):
def __init__(self):
self._options = {}
+ self._defs = None
def get_option(self, option, hostvars=None):
if option not in self._options:
try:
- option_value = C.config.get_config_value(option, plugin_type=get_plugin_class(self), plugin_name=self._load_name, variables=hostvars)
+ option_value = C.config.get_config_value(option, plugin_type=self.plugin_type, plugin_name=self._load_name, variables=hostvars)
except AnsibleError as e:
raise KeyError(to_native(e))
self.set_option(option, option_value)
@@ -69,8 +70,7 @@ class AnsiblePlugin(ABC):
def get_options(self, hostvars=None):
options = {}
- defs = C.config.get_configuration_definitions(plugin_type=get_plugin_class(self), name=self._load_name)
- for option in defs:
+ for option in self.option_definitions.keys():
options[option] = self.get_option(option, hostvars=hostvars)
return options
@@ -85,7 +85,7 @@ class AnsiblePlugin(ABC):
:arg var_options: Dict with either 'connection variables'
:arg direct: Dict with 'direct assignment'
'''
- self._options = C.config.get_plugin_options(get_plugin_class(self), self._load_name, keys=task_keys, variables=var_options, direct=direct)
+ self._options = C.config.get_plugin_options(self.plugin_type, self._load_name, keys=task_keys, variables=var_options, direct=direct)
# allow extras/wildcards from vars that are not directly consumed in configuration
# this is needed to support things like winrm that can have extended protocol options we don't directly handle
@@ -97,6 +97,37 @@ class AnsiblePlugin(ABC):
self.set_options()
return option in self._options
+ @property
+ def plugin_type(self):
+ return self.__class__.__name__.lower().replace('module', '')
+
+ @property
+ def option_definitions(self):
+ if self._defs is None:
+ self._defs = C.config.get_configuration_definitions(plugin_type=self.plugin_type, name=self._load_name)
+ return self._defs
+
def _check_required(self):
# FIXME: standardize required check based on config
pass
+
+
+class AnsibleJinja2Plugin(AnsiblePlugin):
+
+ def __init__(self, function):
+
+ super(AnsibleJinja2Plugin, self).__init__()
+ self._function = function
+
+ @property
+ def plugin_type(self):
+ return self.__class__.__name__.lower().replace('ansiblejinja2', '')
+
+ def _no_options(self, *args, **kwargs):
+ raise NotImplementedError()
+
+ has_option = get_option = get_options = option_definitions = set_option = set_options = _no_options
+
+ @property
+ def j2_function(self):
+ return self._function