simpler approach and dont override role collection

pull/80746/head
Brian Coca 1 year ago
parent 5c189331c7
commit 332f4985bf

@ -47,7 +47,7 @@ class CollectionSearch:
# this will only be called if someone specified a value; call the shared value # this will only be called if someone specified a value; call the shared value
_ensure_default_collection(collection_list=ds) _ensure_default_collection(collection_list=ds)
# ensure 'current's object collection is here', only playbooks and plays should have this property # ensure 'current's object collection is here', only playbooks, plays and roles should have this property
if getattr(self, '_collection', False) and self._collection not in ds: if getattr(self, '_collection', False) and self._collection not in ds:
ds.insert(0, self._collection) ds.insert(0, self._collection)

@ -57,6 +57,9 @@ class RoleDefinition(Base, Conditional, Taggable, CollectionSearch):
self._role_collection = None self._role_collection = None
self._role_basedir = role_basedir self._role_basedir = role_basedir
self._role_params = dict() self._role_params = dict()
if collection_list is None:
self._collection_list = []
else:
self._collection_list = collection_list self._collection_list = collection_list
# def __repr__(self): # def __repr__(self):
@ -154,16 +157,12 @@ class RoleDefinition(Base, Conditional, Taggable, CollectionSearch):
role_tuple = None role_tuple = None
# ensure play collection context
if self._play._collection:
if not self._collection_list:
self._collection_list = [self._play._collection]
elif self._play._collection not in self._collection_list:
self._collection_list.insert(0, self._play._collection)
# try to load as a collection-based role first # try to load as a collection-based role first
if self._collection_list or AnsibleCollectionRef.is_valid_fqcr(role_name): if self._collection_list or AnsibleCollectionRef.is_valid_fqcr(role_name):
role_tuple = _get_collection_role_path(role_name, self._collection_list) role_tuple = _get_collection_role_path(role_name, self._collection_list)
elif self._play._collection:
# ensure play collection context when role does not have one
role_tuple = _get_collection_role_path(role_name, [self._play._collection])
if role_tuple: if role_tuple:
# we found it, stash collection data and return the name/path tuple # we found it, stash collection data and return the name/path tuple
@ -206,7 +205,7 @@ class RoleDefinition(Base, Conditional, Taggable, CollectionSearch):
role_name = os.path.basename(role_name) role_name = os.path.basename(role_name)
return (role_name, role_path) return (role_name, role_path)
searches = (self._collection_list or []) + role_search_paths searches = (self._collection_list) + role_search_paths
raise AnsibleError("the role '%s' was not found in %s" % (role_name, ":".join(searches)), obj=self._ds) raise AnsibleError("the role '%s' was not found in %s" % (role_name, ":".join(searches)), obj=self._ds)
def _split_role_params(self, ds): def _split_role_params(self, ds):

Loading…
Cancel
Save