From e81ec327196f83c3f9aa78e7387f97f71880bc24 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Wed, 29 Jul 2015 19:28:29 -0400 Subject: [PATCH] made galaxy more resilient with bad yaml files and comments/spaces in non yaml files fixes #10641 --- lib/ansible/cli/galaxy.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/ansible/cli/galaxy.py b/lib/ansible/cli/galaxy.py index 59415997e86..d8d5c0112d8 100644 --- a/lib/ansible/cli/galaxy.py +++ b/lib/ansible/cli/galaxy.py @@ -323,11 +323,16 @@ class GalaxyCLI(CLI): if role_file: f = open(role_file, 'r') if role_file.endswith('.yaml') or role_file.endswith('.yml'): - rolesparsed = map(self.parse_requirements_files, yaml.safe_load(f)) + try: + rolesparsed = map(self.parse_requirements_files, yaml.safe_load(f)) + except: + raise AnsibleError("%s does not seem like a valid yaml file" % role_file) roles_left = [GalaxyRole(self.galaxy, **r) for r in rolesparsed] else: # roles listed in a file, one per line for rname in f.readlines(): + if rname.startswith("#") or rname.strip() == '': + continue roles_left.append(GalaxyRole(self.galaxy, rname.strip())) f.close() else: