From 70a519d5163b1cfbf747a34fedd5d56dc82ef620 Mon Sep 17 00:00:00 2001 From: Conner Crosby Date: Wed, 13 Nov 2024 08:04:00 -0500 Subject: [PATCH] Update TaskHasTag example rule used in custom-rules.md (#4401) --- docs/custom-rules.md | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/docs/custom-rules.md b/docs/custom-rules.md index f0288cac90..50b95375ca 100644 --- a/docs/custom-rules.md +++ b/docs/custom-rules.md @@ -53,35 +53,7 @@ class DeprecatedVariableRule(AnsibleLintRule): The following is an example rule that uses the `matchtask` method: ```python -from __future__ import annotations -from typing import TYPE_CHECKING, Union - -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'] - - def matchtask(self, - task: Task, - file: Lintable - | None = None) -> Union[bool, str]: - # 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 task.get("tags"): - return True - return False +{!../examples/rules/task_has_tag.py!} ``` The task argument to `matchtask` contains a number of keys - the critical one is