Skip to content

Commit

Permalink
Update TaskHasTag example rule used in custom-rules.md (#4401)
Browse files Browse the repository at this point in the history
  • Loading branch information
cavcrosby authored Nov 13, 2024
1 parent 8b47b64 commit 70a519d
Showing 1 changed file with 1 addition and 29 deletions.
30 changes: 1 addition & 29 deletions docs/custom-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 70a519d

Please sign in to comment.