Zack Williams | ad45bf0 | 2020-03-04 21:37:20 -0700 | [diff] [blame] | 1 | # SPDX-FileCopyrightText: © 2020 Open Networking Foundation |
| 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | |
| 4 | # NoTags.py |
| 5 | # ansible-lint rule to mark all tags as errors |
| 6 | |
| 7 | from __future__ import absolute_import |
| 8 | from ansiblelint import AnsibleLintRule |
| 9 | |
| 10 | |
| 11 | class NoTags(AnsibleLintRule): |
| 12 | id = "ONF0001" |
| 13 | shortdesc = "Don't use tags to modify runtime behavior" |
| 14 | description = ( |
| 15 | "Tags can change which tasks Ansible performs when running a role or" |
| 16 | "playbook, which is undesirable. Reorganize your roles to not require" |
| 17 | "them, optionally using setup facts or platform vars as workarounds." |
| 18 | ) |
| 19 | tags = ["idiom"] |
| 20 | severity = "HIGH" |
| 21 | |
Zack Williams | dac2be4 | 2021-08-19 16:14:31 -0700 | [diff] [blame] | 22 | def matchtask(self, file, task): # pylint: disable=W0613, R0201 |
Zack Williams | ad45bf0 | 2020-03-04 21:37:20 -0700 | [diff] [blame] | 23 | |
| 24 | # Task should not have tags |
| 25 | if "tags" in task: |
| 26 | |
| 27 | # allow if only tag is the skip_ansible_lint tag |
| 28 | if task["tags"] == ["skip_ansible_lint"]: |
| 29 | return False |
| 30 | |
| 31 | return True |
| 32 | |
| 33 | return False |