From 1ecad5aed2ba51705ec04abf717e80d44490b5dd Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Tue, 20 Oct 2015 14:38:07 -0400 Subject: [PATCH] now galaxy correctly detects empty requirements file also allow for 'scm' and 'src' not to be populated in requirements entries --- lib/ansible/cli/galaxy.py | 10 +++++++++- lib/ansible/playbook/role/requirement.py | 20 +++++++++++--------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/lib/ansible/cli/galaxy.py b/lib/ansible/cli/galaxy.py index 42f3cf2b50..d8b0cee70a 100644 --- a/lib/ansible/cli/galaxy.py +++ b/lib/ansible/cli/galaxy.py @@ -310,7 +310,15 @@ class GalaxyCLI(CLI): try: f = open(role_file, 'r') if role_file.endswith('.yaml') or role_file.endswith('.yml'): - for role in yaml.safe_load(f.read()): + try: + required_roles = yaml.safe_load(f.read()) + except Exception as e: + raise AnsibleError("Unable to load data from the requirements file: %s" % role_file) + + if required_roles is None: + raise AnsibleError("No roles found in file: %s" % role_file) + + for role in required_roles: role = RoleRequirement.role_yaml_parse(role) self.display.debug('found role %s in yaml file' % str(role)) if 'name' not in role and 'scm' not in role: diff --git a/lib/ansible/playbook/role/requirement.py b/lib/ansible/playbook/role/requirement.py index 5de1876c31..86942a9b29 100644 --- a/lib/ansible/playbook/role/requirement.py +++ b/lib/ansible/playbook/role/requirement.py @@ -140,17 +140,19 @@ class RoleRequirement(RoleDefinition): role = RoleRequirement.role_spec_parse(role['role']) else: role = role.copy() - # New style: { src: 'galaxy.role,version,name', other_vars: "here" } - if 'github.com' in role["src"] and 'http' in role["src"] and '+' not in role["src"] and not role["src"].endswith('.tar.gz'): - role["src"] = "git+" + role["src"] - if '+' in role["src"]: - (scm, src) = role["src"].split('+') - role["scm"] = scm - role["src"] = src + if 'src'in role: + # New style: { src: 'galaxy.role,version,name', other_vars: "here" } + if 'github.com' in role["src"] and 'http' in role["src"] and '+' not in role["src"] and not role["src"].endswith('.tar.gz'): + role["src"] = "git+" + role["src"] - if 'name' not in role: - role["name"] = RoleRequirement.repo_url_to_role_name(role["src"]) + if '+' in role["src"]: + (scm, src) = role["src"].split('+') + role["scm"] = scm + role["src"] = src + + if 'name' not in role: + role["name"] = RoleRequirement.repo_url_to_role_name(role["src"]) if 'version' not in role: role['version'] = ''