def matchyaml(self, file: Lintable) -> List["MatchError"]: result: List["MatchError"] = [] path = str(file.path).split("/") if "tasks" in path: role_name = _remove_prefix(path[path.index("tasks") - 1], "ansible-role-") role_root = path[:path.index("tasks")] meta = Path("/".join(role_root)) / "meta" / "main.yml" if meta.is_file(): meta_data = parse_yaml_from_file(str(meta)) if meta_data: try: role_name = meta_data['galaxy_info']['role_name'] except KeyError: pass if role_name not in self.done: self.done.append(role_name) if not self._re.match(role_name): result.append( self.create_matcherror( filename=str(file.path), message=self.__class__.shortdesc.format(role_name), )) return result
def _infer_role_name(self, meta: Path, default: str) -> str: if meta.is_file(): meta_data = parse_yaml_from_file(str(meta)) if meta_data: try: return str(meta_data['galaxy_info']['role_name']) except KeyError: pass return default
def matchyaml(self, file: Lintable) -> List["MatchError"]: """Return matches for variables defined in vars files.""" results: List["MatchError"] = [] meta_data: Dict[str, Any] = {} if str(file.kind) == "vars": meta_data = parse_yaml_from_file(str(file.path)) for key in meta_data.keys(): if self.is_invalid_variable_name(key): results.append( self.create_matcherror( filename=file, # linenumber=vars['__line__'], message="File defines variable '" + key + "' that violates variable naming standards", )) else: results.extend(super().matchyaml(file)) return results
def match(self, file, text): path = file['path'].split("/") if "tasks" in path: meta = Path(file['path']).parent.parent / "meta" / "main.yml" role_name = _remove_prefix(path[path.index("tasks") - 1], "ansible-role-") if meta.is_file(): try: role_name = parse_yaml_from_file( str(meta))['galaxy_info']['role_name'] except KeyError: pass if role_name in self.done: return False self.done.append(role_name) if not re.match(self.ROLE_NAME_REGEXP, role_name): return self.shortdesc.format(role_name) return False