Skip to content

Commit

Permalink
allow plugin loader to load sidecar docs
Browse files Browse the repository at this point in the history
* if you have an inventory plugin (or other non-test/non-filter plugin,
  I'd assume) that has docs only provided via sidecar, then the plugin's
  config defs need to be populated by the sidecar; otherwise, you're
  forced to have a `DOCUMENTATION` attribute in the inventory plugin
  that duplicates the content of the sidecar
  • Loading branch information
guppy0130 committed May 11, 2024
1 parent f7d7890 commit 27c4276
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/ansible/plugins/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,10 +409,17 @@ def _load_config_defs(self, name, module, path):
if type_name in C.CONFIGURABLE_PLUGINS and not C.config.has_configuration_definition(type_name, name):
dstring = AnsibleLoader(getattr(module, 'DOCUMENTATION', ''), file_name=path).get_single_data()

# TODO: allow configurable plugins to use sidecar
# if not dstring:
# filename, cn = find_plugin_docfile( name, type_name, self, [os.path.dirname(path)], C.YAML_DOC_EXTENSIONS)
# # TODO: dstring = AnsibleLoader(, file_name=path).get_single_data()
# allow configurable plugins to use sidecar
if not dstring:
# turns `community.general.module` into just `module`
short_module_name = os.path.splitext(name)[1][1:]
for extension in C.YAML_DOC_EXTENSIONS:
possible_sidecar_file = os.path.join(os.path.dirname(path), short_module_name + extension)
if not os.path.exists(possible_sidecar_file):
continue
with open(possible_sidecar_file) as fp:
dstring = AnsibleLoader(fp).get_single_data().get("DOCUMENTATION", "")
break

if dstring:
add_fragments(dstring, path, fragment_loader=fragment_loader, is_module=(type_name == 'module'))
Expand Down

0 comments on commit 27c4276

Please sign in to comment.