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>
This commit is contained in:
Matt Martz 2020-04-22 13:58:08 -05:00 committed by GitHub
parent 977b58740b
commit da98fc267a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 4 deletions

View file

@ -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)

View file

@ -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):
'''

View file

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

View file

@ -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

View file

@ -0,0 +1,2 @@
- set_fact:
standalone_role_var: True