2021-01-30 15:52:48 +00:00
|
|
|
import re
|
|
|
|
|
|
|
|
from ansiblelater.standard import StandardBase
|
|
|
|
|
|
|
|
|
|
|
|
class CheckLiteralBoolFormat(StandardBase):
|
|
|
|
|
|
|
|
sid = "ANSIBLE0014"
|
2021-10-07 20:59:39 +00:00
|
|
|
description = "Literal bools should be consistent"
|
|
|
|
helptext = "literal bools should be written as `{bools}`"
|
2021-01-30 15:52:48 +00:00
|
|
|
version = "0.1"
|
2023-06-28 07:14:39 +00:00
|
|
|
types = ["playbook", "task", "handler", "rolevars", "hostvars", "groupvars"]
|
2021-01-30 15:52:48 +00:00
|
|
|
|
|
|
|
def check(self, candidate, settings):
|
|
|
|
yamllines, errors = self.get_normalized_yaml(candidate, settings)
|
|
|
|
|
2021-10-07 20:59:39 +00:00
|
|
|
litera_bools = re.compile(r"(?:[=!]=|:)\s*(true|false|yes|no|on|off)\s*$", re.IGNORECASE)
|
|
|
|
allowed = settings["ansible"]["literal-bools"]
|
2021-01-30 15:52:48 +00:00
|
|
|
|
|
|
|
if not errors:
|
|
|
|
for i, line in yamllines:
|
2021-10-07 20:59:39 +00:00
|
|
|
matches = litera_bools.findall(line)
|
|
|
|
if any(m not in allowed for m in matches):
|
|
|
|
errors.append(self.Error(i, self.helptext.format(bools=", ".join(allowed))))
|
2021-01-30 15:52:48 +00:00
|
|
|
|
|
|
|
return self.Result(candidate.path, errors)
|