summaryrefslogtreecommitdiff
path: root/lib/ansible/plugins/list.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ansible/plugins/list.py')
-rw-r--r--lib/ansible/plugins/list.py42
1 files changed, 18 insertions, 24 deletions
diff --git a/lib/ansible/plugins/list.py b/lib/ansible/plugins/list.py
index cd4d51f5..e09b293f 100644
--- a/lib/ansible/plugins/list.py
+++ b/lib/ansible/plugins/list.py
@@ -11,10 +11,10 @@ from ansible import context
from ansible import constants as C
from ansible.collections.list import list_collections
from ansible.errors import AnsibleError
-from ansible.module_utils.common.text.converters import to_native, to_bytes
+from ansible.module_utils._text import to_native, to_bytes
from ansible.plugins import loader
from ansible.utils.display import Display
-from ansible.utils.collection_loader._collection_finder import _get_collection_path
+from ansible.utils.collection_loader._collection_finder import _get_collection_path, AnsibleCollectionRef
display = Display()
@@ -44,7 +44,6 @@ def get_composite_name(collection, name, path, depth):
def _list_plugins_from_paths(ptype, dirs, collection, depth=0):
- # TODO: update to use importlib.resources
plugins = {}
@@ -118,7 +117,6 @@ def _list_j2_plugins_from_file(collection, plugin_path, ptype, plugin_name):
def list_collection_plugins(ptype, collections, search_paths=None):
- # TODO: update to use importlib.resources
# starts at {plugin_name: filepath, ...}, but changes at the end
plugins = {}
@@ -171,32 +169,28 @@ def list_collection_plugins(ptype, collections, search_paths=None):
return plugins
-def list_plugins(ptype, collections=None, search_paths=None):
- if isinstance(collections, str):
- collections = [collections]
+def list_plugins(ptype, collection=None, search_paths=None):
# {plugin_name: (filepath, class), ...}
plugins = {}
- plugin_collections = {}
- if collections is None:
+ collections = {}
+ if collection is None:
# list all collections, add synthetic ones
- plugin_collections['ansible.builtin'] = b''
- plugin_collections['ansible.legacy'] = b''
- plugin_collections.update(list_collections(search_paths=search_paths, dedupe=True))
+ collections['ansible.builtin'] = b''
+ collections['ansible.legacy'] = b''
+ collections.update(list_collections(search_paths=search_paths, dedupe=True))
+ elif collection == 'ansible.legacy':
+ # add builtin, since legacy also resolves to these
+ collections[collection] = b''
+ collections['ansible.builtin'] = b''
else:
- for collection in collections:
- if collection == 'ansible.legacy':
- # add builtin, since legacy also resolves to these
- plugin_collections[collection] = b''
- plugin_collections['ansible.builtin'] = b''
- else:
- try:
- plugin_collections[collection] = to_bytes(_get_collection_path(collection))
- except ValueError as e:
- raise AnsibleError("Cannot use supplied collection {0}: {1}".format(collection, to_native(e)), orig_exc=e)
+ try:
+ collections[collection] = to_bytes(_get_collection_path(collection))
+ except ValueError as e:
+ raise AnsibleError("Cannot use supplied collection {0}: {1}".format(collection, to_native(e)), orig_exc=e)
- if plugin_collections:
- plugins.update(list_collection_plugins(ptype, plugin_collections))
+ if collections:
+ plugins.update(list_collection_plugins(ptype, collections))
return plugins