diff options
Diffstat (limited to 'lib/ansible/collections')
-rw-r--r-- | lib/ansible/collections/list.py | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/lib/ansible/collections/list.py b/lib/ansible/collections/list.py index a1d9901706..c6af77a364 100644 --- a/lib/ansible/collections/list.py +++ b/lib/ansible/collections/list.py @@ -69,33 +69,34 @@ def list_collection_dirs(search_paths=None, coll_filter=None): collections = defaultdict(dict) for path in list_valid_collection_paths(search_paths): - b_path = to_bytes(path) - if os.path.isdir(b_path): - b_coll_root = to_bytes(os.path.join(path, 'ansible_collections')) + if os.path.basename(path) != 'ansible_collections': + path = os.path.join(path, 'ansible_collections') + + b_coll_root = to_bytes(path, errors='surrogate_or_strict') - if os.path.exists(b_coll_root) and os.path.isdir(b_coll_root): + if os.path.exists(b_coll_root) and os.path.isdir(b_coll_root): - if namespace is None: - namespaces = os.listdir(b_coll_root) - else: - namespaces = [namespace] + if namespace is None: + namespaces = os.listdir(b_coll_root) + else: + namespaces = [namespace] - for ns in namespaces: - b_namespace_dir = os.path.join(b_coll_root, to_bytes(ns)) + for ns in namespaces: + b_namespace_dir = os.path.join(b_coll_root, to_bytes(ns)) - if os.path.isdir(b_namespace_dir): + if os.path.isdir(b_namespace_dir): - if collection is None: - colls = os.listdir(b_namespace_dir) - else: - colls = [collection] + if collection is None: + colls = os.listdir(b_namespace_dir) + else: + colls = [collection] - for mycoll in colls: + for mycoll in colls: - # skip dupe collections as they will be masked in execution - if mycoll not in collections[ns]: - b_coll = to_bytes(mycoll) - b_coll_dir = os.path.join(b_namespace_dir, b_coll) - if is_collection_path(b_coll_dir): - collections[ns][mycoll] = b_coll_dir - yield b_coll_dir + # skip dupe collections as they will be masked in execution + if mycoll not in collections[ns]: + b_coll = to_bytes(mycoll) + b_coll_dir = os.path.join(b_namespace_dir, b_coll) + if is_collection_path(b_coll_dir): + collections[ns][mycoll] = b_coll_dir + yield b_coll_dir |