diff --git a/changelogs/fragments/adoc_noext_fix.yml b/changelogs/fragments/adoc_noext_fix.yml new file mode 100644 index 00000000000..8dbf06a77d7 --- /dev/null +++ b/changelogs/fragments/adoc_noext_fix.yml @@ -0,0 +1,2 @@ +bugfixes: +- ansible-doc will no longer ignore docs for modules without an extension (https://github.com/ansible/ansible/issues/85279). diff --git a/lib/ansible/plugins/list.py b/lib/ansible/plugins/list.py index b040bbd4004..11a6e00a266 100644 --- a/lib/ansible/plugins/list.py +++ b/lib/ansible/plugins/list.py @@ -58,7 +58,7 @@ def get_composite_name(collection, name, path, depth): return '.'.join(composite) -def _list_plugins_from_paths(ptype, dirs, collection, depth=0): +def _list_plugins_from_paths(ptype, dirs, collection, depth=0, docs=False): # TODO: update to use importlib.resources plugins = {} @@ -93,14 +93,15 @@ def _list_plugins_from_paths(ptype, dirs, collection, depth=0): continue # actually recurse dirs - plugins.update(_list_plugins_from_paths(ptype, [to_native(full_path)], collection, depth=depth + 1)) + plugins.update(_list_plugins_from_paths(ptype, [to_native(full_path)], collection, depth=depth + 1, docs=docs)) else: if any([ plugin in C.IGNORE_FILES, # general files to ignore to_native(b_ext) in C.REJECT_EXTS, # general extensions to ignore - b_ext in (b'.yml', b'.yaml', b'.json'), # ignore docs files TODO: constant! + b_ext in (b'.yml', b'.yaml', b'.json'), # ignore docs files plugin in IGNORE.get(bkey, ()), # plugin in reject list os.path.islink(full_path), # skip aliases, author should document in 'aliases' field + not docs and b_ext in (b''), # ignore no ext when looking for docs files ]): continue @@ -179,7 +180,7 @@ def _list_collection_plugins_with_info( # raise Exception('bad acr for %s, %s' % (collection, ptype)) - plugin_paths.update(_list_plugins_from_paths(ptype, dirs, collection)) + plugin_paths.update(_list_plugins_from_paths(ptype, dirs, collection, docs=True)) plugins = {} if ptype in ('module',): diff --git a/test/integration/targets/ansible-doc/library/bogus_facts b/test/integration/targets/ansible-doc/library/bogus_facts new file mode 100644 index 00000000000..a6e60dc1719 --- /dev/null +++ b/test/integration/targets/ansible-doc/library/bogus_facts @@ -0,0 +1,6 @@ +#!/bin/sh + +echo '{ + "changed": false, + "ansible_facts": {"nothing": "to report"}, +}' diff --git a/test/integration/targets/ansible-doc/library/bogus_facts.py b/test/integration/targets/ansible-doc/library/bogus_facts.py new file mode 100644 index 00000000000..a2d0ab35862 --- /dev/null +++ b/test/integration/targets/ansible-doc/library/bogus_facts.py @@ -0,0 +1,6 @@ +DOCUMENTATION = """ + module: bogus_facts + short_description: bad facts returned + version_added: historical + description: bogus facts for testing +""" diff --git a/test/integration/targets/ansible-doc/library/facts_one b/test/integration/targets/ansible-doc/library/facts_one new file mode 100644 index 00000000000..7ade37c54ff --- /dev/null +++ b/test/integration/targets/ansible-doc/library/facts_one @@ -0,0 +1,6 @@ +#!/bin/sh + +echo '{ + "changed": false, + "ansible_facts": {"factsone": "from facts_one module"} +}' diff --git a/test/integration/targets/ansible-doc/library/facts_one.yml b/test/integration/targets/ansible-doc/library/facts_one.yml new file mode 100644 index 00000000000..875096f7a0f --- /dev/null +++ b/test/integration/targets/ansible-doc/library/facts_one.yml @@ -0,0 +1,5 @@ +DOCUMENTATION: + module: facts_one + short_description: random facts returned + version_added: historical + description: random facts for testing diff --git a/test/integration/targets/ansible-doc/runme.sh b/test/integration/targets/ansible-doc/runme.sh index aac87c072d4..f135adde744 100755 --- a/test/integration/targets/ansible-doc/runme.sh +++ b/test/integration/targets/ansible-doc/runme.sh @@ -281,3 +281,9 @@ test "$(ansible-doc -l -t module --playbook-dir ./ 2>&1 1>/dev/null |grep -c "no echo "testing without playbook dir, builtin should return" ansible-doc -t filter split -v 2>&1 |grep "${GREP_OPTS[@]}" -v histerical + +echo "test 'sidecar' for no extension module with .py doc" +[ "$(ansible-doc -M ./library -l ansible.legacy |grep -v 'UNDOCUMENTED' |grep -c bogus_facts)" == "1" ] + +echo "test 'sidecar' for no extension module with .yml doc" +[ "$(ansible-doc -M ./library -l ansible.legacy |grep -v 'UNDOCUMENTED' |grep -c facts_one)" == "1" ] diff --git a/test/sanity/ignore.txt b/test/sanity/ignore.txt index e21d0ce1441..94c4b8c35e0 100644 --- a/test/sanity/ignore.txt +++ b/test/sanity/ignore.txt @@ -60,6 +60,8 @@ lib/ansible/_internal/_wrapt.py mypy-3.13!skip # vendored code lib/ansible/_internal/_wrapt.py pep8!skip # vendored code lib/ansible/_internal/_wrapt.py pylint!skip # vendored code lib/ansible/_internal/ansible_collections/ansible/_protomatter/README.md no-unwanted-files +test/integration/targets/ansible-doc/library/bogus_facts shebang +test/integration/targets/ansible-doc/library/facts_one shebang test/integration/targets/ansible-test-sanity/ansible_collections/ns/col/tests/integration/targets/hello/files/bad.py pylint:ansible-bad-function # ignore, required for testing test/integration/targets/ansible-test-sanity/ansible_collections/ns/col/tests/integration/targets/hello/files/bad.py pylint:ansible-bad-import-from # ignore, required for testing test/integration/targets/ansible-test-sanity/ansible_collections/ns/col/tests/integration/targets/hello/files/bad.py pylint:ansible-bad-import # ignore, required for testing