mirror of
https://github.com/ansible/ansible.git
synced 2026-08-03 08:03:05 +02:00
Make sure ansible-doc doesn't crash when scanning collections whose path contains ansible_collections twice (#85361) (#85930)
Ref: https://github.com/ansible/ansible/issues/84909#issuecomment-2767335761
(cherry picked from commit c6d8d206af)
Co-authored-by: s-hertel <19572925+s-hertel@users.noreply.github.com>
Co-authored-by: Brian Coca <bcoca@users.noreply.github.com>
This commit is contained in:
co-authored by
s-hertel
Brian Coca
parent
41ac662dec
commit
81d883687e
@@ -0,0 +1,3 @@
|
|||||||
|
bugfixes:
|
||||||
|
- "ansible-doc - prevent crash when scanning collections in paths that have more than one ``ansible_collections`` in it
|
||||||
|
(https://github.com/ansible/ansible/issues/84909, https://github.com/ansible/ansible/pull/85361)."
|
||||||
@@ -237,7 +237,9 @@ class RoleMixin(object):
|
|||||||
b_colldirs = list_collection_dirs(coll_filter=collection_filter)
|
b_colldirs = list_collection_dirs(coll_filter=collection_filter)
|
||||||
for b_path in b_colldirs:
|
for b_path in b_colldirs:
|
||||||
path = to_text(b_path, errors='surrogate_or_strict')
|
path = to_text(b_path, errors='surrogate_or_strict')
|
||||||
collname = _get_collection_name_from_path(b_path)
|
if not (collname := _get_collection_name_from_path(b_path)):
|
||||||
|
display.debug(f'Skipping invalid path {b_path!r}')
|
||||||
|
continue
|
||||||
|
|
||||||
roles_dir = os.path.join(path, 'roles')
|
roles_dir = os.path.join(path, 'roles')
|
||||||
if os.path.exists(roles_dir):
|
if os.path.exists(roles_dir):
|
||||||
|
|||||||
@@ -17,8 +17,10 @@ def list_collections(coll_filter=None, search_paths=None, dedupe=True, artifacts
|
|||||||
|
|
||||||
collections = {}
|
collections = {}
|
||||||
for candidate in list_collection_dirs(search_paths=search_paths, coll_filter=coll_filter, artifacts_manager=artifacts_manager, dedupe=dedupe):
|
for candidate in list_collection_dirs(search_paths=search_paths, coll_filter=coll_filter, artifacts_manager=artifacts_manager, dedupe=dedupe):
|
||||||
collection = _get_collection_name_from_path(candidate)
|
if collection := _get_collection_name_from_path(candidate):
|
||||||
collections[collection] = candidate
|
collections[collection] = candidate
|
||||||
|
else:
|
||||||
|
display.debug(f'Skipping invalid collection in path: {candidate!r}')
|
||||||
return collections
|
return collections
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -211,6 +211,13 @@ ANSIBLE_LIBRARY='./nolibrary' ansible-doc --metadata-dump --no-fail-on-errors --
|
|||||||
output=$(ANSIBLE_LIBRARY='./nolibrary' ansible-doc --metadata-dump --playbook-dir broken-docs testns.testcol 2>&1 | grep -c 'ERROR' || true)
|
output=$(ANSIBLE_LIBRARY='./nolibrary' ansible-doc --metadata-dump --playbook-dir broken-docs testns.testcol 2>&1 | grep -c 'ERROR' || true)
|
||||||
test "${output}" -eq 1
|
test "${output}" -eq 1
|
||||||
|
|
||||||
|
# ensure --metadata-dump does not crash if the ansible_collections is nested (https://github.com/ansible/ansible/issues/84909)
|
||||||
|
testdir="$(pwd)"
|
||||||
|
pbdir="collections/ansible_collections/testns/testcol/playbooks"
|
||||||
|
cd "$pbdir"
|
||||||
|
ANSIBLE_COLLECTIONS_PATH="$testdir/$pbdir/collections" ansible-doc -vvv --metadata-dump --no-fail-on-errors
|
||||||
|
cd "$testdir"
|
||||||
|
|
||||||
echo "test doc list on broken role metadata"
|
echo "test doc list on broken role metadata"
|
||||||
# ensure that role doc does not fail when --no-fail-on-errors is supplied
|
# ensure that role doc does not fail when --no-fail-on-errors is supplied
|
||||||
ANSIBLE_LIBRARY='./nolibrary' ansible-doc --no-fail-on-errors --playbook-dir broken-docs testns.testcol.testrole -t role 1>/dev/null 2>&1
|
ANSIBLE_LIBRARY='./nolibrary' ansible-doc --no-fail-on-errors --playbook-dir broken-docs testns.testcol.testrole -t role 1>/dev/null 2>&1
|
||||||
|
|||||||
Reference in New Issue
Block a user