diff --git a/changelogs/fragments/collection-prefix-basedir.yaml b/changelogs/fragments/collection-prefix-basedir.yaml new file mode 100644 index 00000000000..674de8043f9 --- /dev/null +++ b/changelogs/fragments/collection-prefix-basedir.yaml @@ -0,0 +1,2 @@ +bugfixes: +- Fix issue where the collection loader tracebacks if ``collections_paths = ./`` is set in the config diff --git a/lib/ansible/utils/collection_loader.py b/lib/ansible/utils/collection_loader.py index cc7e4df54c0..0fc18948c92 100644 --- a/lib/ansible/utils/collection_loader.py +++ b/lib/ansible/utils/collection_loader.py @@ -519,7 +519,7 @@ def get_collection_name_from_path(path): # strip off the common prefix (handle weird testing cases of nested collection roots, eg) collection_remnant = n_path[len(coll_path):] # commonprefix may include the trailing /, prepend to the remnant if necessary (eg trailing / on root) - if collection_remnant[0] != '/': + if collection_remnant and collection_remnant[0] != '/': collection_remnant = '/' + collection_remnant # the path lives under this collection root, see if it maps to a collection found_collection = _N_COLLECTION_PATH_RE.search(collection_remnant)