diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-14 20:04:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-14 20:04:50 +0000 |
commit | 782f8df6e41f29dce2db4970a3ad84aaeb7d8c5f (patch) | |
tree | 3a88a542cd8074743d251881131510157cfc510b /examples/rules | |
parent | Initial commit. (diff) | |
download | ansible-lint-782f8df6e41f29dce2db4970a3ad84aaeb7d8c5f.tar.xz ansible-lint-782f8df6e41f29dce2db4970a3ad84aaeb7d8c5f.zip |
Adding upstream version 4.3.7.upstream/4.3.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'examples/rules')
-rw-r--r-- | examples/rules/TaskHasTag.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/examples/rules/TaskHasTag.py b/examples/rules/TaskHasTag.py new file mode 100644 index 0000000..58dfa7c --- /dev/null +++ b/examples/rules/TaskHasTag.py @@ -0,0 +1,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 |