From 2fe34b6444502079dc0b84365ce82dbc92de308e Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 14:06:49 +0200 Subject: Adding upstream version 6.17.2. Signed-off-by: Daniel Baumann --- examples/rules/task_has_tag.py | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 examples/rules/task_has_tag.py (limited to 'examples/rules/task_has_tag.py') diff --git a/examples/rules/task_has_tag.py b/examples/rules/task_has_tag.py new file mode 100644 index 0000000..a4b927c --- /dev/null +++ b/examples/rules/task_has_tag.py @@ -0,0 +1,44 @@ +"""Example implementation of a rule requiring tasks to have tags set.""" +from __future__ import annotations + +from typing import TYPE_CHECKING + +from ansiblelint.rules import AnsibleLintRule + +if TYPE_CHECKING: + from ansiblelint.file_utils import Lintable + from ansiblelint.utils import Task + + +class TaskHasTag(AnsibleLintRule): + """Tasks must have tag.""" + + id = "EXAMPLE001" + description = "Tasks must have tag" + tags = ["productivity", "tags"] + + def matchtask( + self, + task: Task, + file: Lintable | None = None, + ) -> bool | str: + """Task matching method.""" + if isinstance(task, str): + return False + + # If the task include another task or make the playbook fail + # Don't force to have a tag + if not set(task.keys()).isdisjoint(["include", "fail"]): + return False + + if not set(task.keys()).isdisjoint(["include_tasks", "fail"]): + return False + + if not set(task.keys()).isdisjoint(["import_tasks", "fail"]): + return False + + # Task should have tags + if "tags" not in task: + return True + + return False -- cgit v1.2.3