diff --git a/lib/ansible/cli/galaxy.py b/lib/ansible/cli/galaxy.py index ad055ce9c2f..035f47dbd77 100644 --- a/lib/ansible/cli/galaxy.py +++ b/lib/ansible/cli/galaxy.py @@ -608,8 +608,9 @@ class GalaxyCLI(CLI): else: # Newer format with a collections and/or roles key - extra_keys = set(file_requirements.keys()).difference(set(['roles', 'collections'])) - if extra_keys: + is_galaxy_yml = set(file_requirements.keys()).issuperset(['name', 'namespace']) + extra_keys = set(file_requirements.keys()).difference(['roles', 'collections']) + if extra_keys and not is_galaxy_yml: raise AnsibleError("Expecting only 'roles' and/or 'collections' as base keys in the requirements " "file. Found: %s" % (to_native(", ".join(extra_keys)))) @@ -641,6 +642,10 @@ class GalaxyCLI(CLI): else: requirements['collections'].append((collection_req, '*', None, None)) + if is_galaxy_yml: + for req_name, req_version in (file_requirements.get('dependencies') or {}).items(): + requirements['collections'].append((req_name, req_version, None, None)) + return requirements @staticmethod