made galaxy more resilient with bad yaml files and comments/spaces in non yaml files

fixes #10641
pull/11791/head
Brian Coca 9 years ago
parent 63b54a3271
commit e81ec32719

@ -323,11 +323,16 @@ class GalaxyCLI(CLI):
if role_file: if role_file:
f = open(role_file, 'r') f = open(role_file, 'r')
if role_file.endswith('.yaml') or role_file.endswith('.yml'): if role_file.endswith('.yaml') or role_file.endswith('.yml'):
try:
rolesparsed = map(self.parse_requirements_files, yaml.safe_load(f)) 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] roles_left = [GalaxyRole(self.galaxy, **r) for r in rolesparsed]
else: else:
# roles listed in a file, one per line # roles listed in a file, one per line
for rname in f.readlines(): for rname in f.readlines():
if rname.startswith("#") or rname.strip() == '':
continue
roles_left.append(GalaxyRole(self.galaxy, rname.strip())) roles_left.append(GalaxyRole(self.galaxy, rname.strip()))
f.close() f.close()
else: else:

Loading…
Cancel
Save