2024-01-25 20:40:15 +00:00
|
|
|
from ansiblelater.rule import RuleBase
|
2021-01-30 15:52:48 +00:00
|
|
|
|
|
|
|
|
2024-01-25 20:40:15 +00:00
|
|
|
class CheckNamedTask(RuleBase):
|
2024-01-27 18:56:35 +00:00
|
|
|
rid = "ANS106"
|
2021-01-30 15:52:48 +00:00
|
|
|
description = "Tasks and handlers must be named"
|
2024-01-25 20:40:15 +00:00
|
|
|
helptext = "module `{module}` used without or empty `name` attribute"
|
2021-01-30 15:52:48 +00:00
|
|
|
types = ["playbook", "task", "handler"]
|
|
|
|
|
|
|
|
def check(self, candidate, settings):
|
|
|
|
tasks, errors = self.get_normalized_tasks(candidate, settings)
|
2021-10-10 20:59:52 +00:00
|
|
|
exclude_modules = settings["ansible"]["named-task"]["exclude"]
|
2021-01-30 15:52:48 +00:00
|
|
|
|
|
|
|
if not errors:
|
|
|
|
for task in tasks:
|
|
|
|
module = task["action"]["__ansible_module__"]
|
2021-10-10 20:59:52 +00:00
|
|
|
if ("name" not in task or not task["name"]) and module not in exclude_modules:
|
2021-01-30 15:52:48 +00:00
|
|
|
errors.append(
|
|
|
|
self.Error(task["__line__"], self.helptext.format(module=module))
|
|
|
|
)
|
|
|
|
|
|
|
|
return self.Result(candidate.path, errors)
|