Allow a collection role to call a standalone role by default (#69102)

* Allow a collection role to call a standalone role by default. Fixes #69101

* tweaked changelog text

* Guard against NoneType

Co-authored-by: Matt Davis <nitzmahone@users.noreply.github.com>
pull/69115/head
Matt Martz 4 years ago committed by GitHub
parent 977b58740b
commit da98fc267a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,5 @@
bugfixes:
- Collections - Allow a collection role to call a stand alone role, without
needing to explicitly add ``ansible.legacy`` to the collection search
order within the collection role.
(https://github.com/ansible/ansible/issues/69101)

@ -162,9 +162,9 @@ class RoleDefinition(Base, Conditional, Taggable, CollectionSearch):
self._role_collection = role_tuple[2]
return role_tuple[0:2]
# FUTURE: refactor this to be callable from internal so we can properly order ansible.legacy searches with the collections keyword
if self._collection_list and 'ansible.legacy' not in self._collection_list:
raise AnsibleError("the role '%s' was not found in %s" % (role_name, ":".join(self._collection_list)), obj=self._ds)
# We didn't find a collection role, look in defined role paths
# FUTURE: refactor this to be callable from internal so we can properly order
# ansible.legacy searches with the collections keyword
# we always start the search for roles in the base directory of the playbook
role_search_paths = [
@ -198,7 +198,8 @@ class RoleDefinition(Base, Conditional, Taggable, CollectionSearch):
role_name = os.path.basename(role_name)
return (role_name, role_path)
raise AnsibleError("the role '%s' was not found in %s" % (role_name, ":".join(role_search_paths)), obj=self._ds)
searches = (self._collection_list or []) + role_search_paths
raise AnsibleError("the role '%s' was not found in %s" % (role_name, ":".join(searches)), obj=self._ds)
def _split_role_params(self, ds):
'''

@ -0,0 +1,6 @@
- include_role:
name: standalone
- assert:
that:
- standalone_role_var is defined

@ -401,3 +401,8 @@
handler_counter: 0
roles:
- testns.testcoll.test_fqcn_handlers
- name: Ensure a collection role can call a standalone role
hosts: testhost
roles:
- testns.testcoll.call_standalone

Loading…
Cancel
Save