mirror of
https://github.com/thegeeklab/ansible-later.git
synced 2024-11-01 02:40:40 +00:00
Robert Kaussow
43d7edca32
* refactor plugin system to use a class-based approach * disable some docstring linter errors and fix imports * cleanup * fix docs * add metavars to cli arguments for better helptext * add option to disable buildin rules * remove print * remove dead code
28 lines
904 B
Python
28 lines
904 B
Python
from collections import defaultdict
|
|
|
|
from ansiblelater.standard import StandardBase
|
|
|
|
|
|
class CheckUniqueNamedTask(StandardBase):
|
|
|
|
sid = "ANSIBLE0003"
|
|
description = "Tasks and handlers must be uniquely named within a single file"
|
|
helptext = "name '{name}' appears multiple times"
|
|
version = "0.1"
|
|
types = ["playbook", "task", "handler"]
|
|
|
|
def check(self, candidate, settings):
|
|
tasks, errors = self.get_normalized_tasks(candidate, settings)
|
|
|
|
namelines = defaultdict(list)
|
|
|
|
if not errors:
|
|
for task in tasks:
|
|
if "name" in task:
|
|
namelines[task["name"]].append(task["__line__"])
|
|
for (name, lines) in namelines.items():
|
|
if name and len(lines) > 1:
|
|
errors.append(self.Error(lines[-1], self.helptext.format(name=name)))
|
|
|
|
return self.Result(candidate.path, errors)
|