2021-01-30 15:52:48 +00:00
|
|
|
from ansiblelater.standard import StandardBase
|
|
|
|
|
|
|
|
|
|
|
|
class CheckNamedTask(StandardBase):
|
|
|
|
|
|
|
|
sid = "ANSIBLE0006"
|
|
|
|
description = "Tasks and handlers must be named"
|
|
|
|
helptext = "module '{module}' used without or empty `name` attribute"
|
|
|
|
version = "0.1"
|
2023-06-28 07:14:39 +00:00
|
|
|
types = ["playbook", "task", "handler"]
|
2021-01-30 15:52:48 +00:00
|
|
|
|
|
|
|
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)
|