ansible-later/ansiblelater/rules/CheckMetaMain.py
Robert Kaussow 2df48598ec
refactor: drop default standards version and rename to rules (#752)
BREAKING CHANGE: The option to define a `Standards` version has been removed. Every new rule that is added on upcoming releases is activated by default and will also create errors if triggered. The behavior of rules can be controlled by the existing `rules.exclude_filter` or `rules.warning_filter` options.

BREAKING CHANGE: The option `rules.buildin` has been renamed to `rules.builtin`.

BREAKING CHANGE: The option `rules.standards` has been renamed to `rules.dir`.

BREAKING CHANGE: The option `rules.filter` has been renamed to `rules.include_filter`.
2024-01-25 21:40:15 +01:00

31 lines
1.1 KiB
Python

from nested_lookup import nested_lookup
from ansiblelater.rule import RuleBase
class CheckMetaMain(RuleBase):
sid = "ANSIBLE0002"
description = "Roles must contain suitable meta/main.yml"
helptext = "file should contain `{key}` key"
types = ["meta"]
def check(self, candidate, settings):
content, errors = self.get_raw_yaml(candidate, settings)
keys = ["author", "description", "min_ansible_version", "platforms"]
if not errors:
has_galaxy_info = isinstance(content, dict) and "galaxy_info" in content
has_dependencies = isinstance(content, dict) and "dependencies" in content
if not has_galaxy_info:
errors.append(self.Error(None, self.helptext.format(key="galaxy_info")))
if not has_dependencies:
errors.append(self.Error(None, self.helptext.format(key="dependencies")))
for key in keys:
if has_galaxy_info and not nested_lookup(key, content.get("galaxy_info", {})):
errors.append(self.Error(None, self.helptext.format(key=key)))
return self.Result(candidate.path, errors)