blob: 58dfa7c62b4110ac21a1d01c30efc507746d8e8a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
"""Example implementation of a rule requiring tasks to have tags set."""
from ansiblelint.rules import AnsibleLintRule
class TaskHasTag(AnsibleLintRule):
"""Tasks must have tag."""
id = 'EXAMPLE001'
shortdesc = 'Tasks must have tag'
description = 'Tasks must have tag'
tags = ['productivity', 'tags']
def matchtask(self, file, task):
"""Task matching method."""
# The meta files don't have tags
if file['type'] in ["meta", "playbooks"]:
return False
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
|