From 327c9f53ef8b087da6eda3eefe7ea44a9a2b80c4 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Mon, 16 Nov 2020 11:02:11 -0600 Subject: [PATCH] Allow using galaxy.yml as a requirements file --- lib/ansible/cli/galaxy.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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