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, 24 insertions, 18 deletions
diff --git a/lib/ansible/plugins/list.py b/lib/ansible/plugins/list.py
index e09b293f..cd4d51f5 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._text import to_native, to_bytes
+from ansible.module_utils.common.text.converters 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, AnsibleCollectionRef
+from ansible.utils.collection_loader._collection_finder import _get_collection_path
display = Display()
@@ -44,6 +44,7 @@ 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 = {}
@@ -117,6 +118,7 @@ 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 = {}
@@ -169,28 +171,32 @@ def list_collection_plugins(ptype, collections, search_paths=None):
return plugins
-def list_plugins(ptype, collection=None, search_paths=None):
+def list_plugins(ptype, collections=None, search_paths=None):
+ if isinstance(collections, str):
+ collections = [collections]
# {plugin_name: (filepath, class), ...}
plugins = {}
- collections = {}
- if collection is None:
+ plugin_collections = {}
+ if collections is None:
# list all collections, add synthetic ones
- 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''
+ plugin_collections['ansible.builtin'] = b''
+ plugin_collections['ansible.legacy'] = b''
+ plugin_collections.update(list_collections(search_paths=search_paths, dedupe=True))
else:
- 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)
+ 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)
- if collections:
- plugins.update(list_collection_plugins(ptype, collections))
+ if plugin_collections:
+ plugins.update(list_collection_plugins(ptype, plugin_collections))
return plugins