1"""Constants used by AnsibleLint.""" 2import os.path 3import sys 4 5# mypy/pylint idiom for py36-py38 compatibility 6# https://github.com/python/typeshed/issues/3500#issuecomment-560958608 7if sys.version_info >= (3, 8): 8 from typing import Literal # pylint: disable=no-name-in-module 9else: 10 from typing_extensions import Literal 11 12DEFAULT_RULESDIR = os.path.join(os.path.dirname(__file__), 'rules') 13CUSTOM_RULESDIR_ENVVAR = "ANSIBLE_LINT_CUSTOM_RULESDIR" 14 15INVALID_CONFIG_RC = 2 16ANSIBLE_FAILURE_RC = 3 17ANSIBLE_MISSING_RC = 4 18INVALID_PREREQUISITES_RC = 10 19EXIT_CONTROL_C_RC = 130 20 21# Minimal version of Ansible we support for runtime 22ANSIBLE_MIN_VERSION = "2.9" 23 24# Based on https://docs.ansible.com/ansible/latest/reference_appendices/config.html 25ANSIBLE_DEFAULT_ROLES_PATH = ( 26 "~/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles" 27) 28 29ANSIBLE_MOCKED_MODULE = """\ 30# This is a mocked Ansible module generated by ansible-lint 31from ansible.module_utils.basic import AnsibleModule 32 33DOCUMENTATION = ''' 34module: {name} 35 36short_description: Mocked 37version_added: "1.0.0" 38description: Mocked 39 40author: 41 - ansible-lint (@nobody) 42''' 43EXAMPLES = '''mocked''' 44RETURN = '''mocked''' 45 46 47def main(): 48 result = dict( 49 changed=False, 50 original_message='', 51 message='') 52 53 module = AnsibleModule( 54 argument_spec=dict(), 55 supports_check_mode=True, 56 ) 57 module.exit_json(**result) 58 59 60if __name__ == "__main__": 61 main() 62""" 63 64FileType = Literal[ 65 "playbook", 66 "meta", # role meta 67 "tasks", # includes pre_tasks, post_tasks 68 "handlers", # very similar to tasks but with some specificts 69 # https://docs.ansible.com/ansible/latest/galaxy/user_guide.html#installing-roles-and-collections-from-the-same-requirements-yml-file 70 "requirements", 71 "role", # that is a folder! 72 "yaml", # generic yaml file, previously reported as unknown file type 73 "", # unknown file type 74] 75 76 77# odict is the base class used to represent data model of Ansible 78# playbooks and tasks. 79odict = dict 80if sys.version_info[:2] < (3, 7): 81 try: 82 # pylint: disable=unused-import 83 from collections import OrderedDict as odict # noqa: 401 84 except ImportError: 85 pass 86 87# Deprecated tags/ids and their newer names 88RENAMED_TAGS = { 89 '102': 'no-jinja-when', 90 '104': 'deprecated-bare-vars', 91 '105': 'deprecated-module', 92 '106': 'role-name', 93 '202': 'risky-octal', 94 '203': 'no-tabs', 95 '205': 'playbook-extension', 96 '206': 'var-spacing', 97 '207': 'no-jinja-nesting', 98 '208': 'risky-file-permissions', 99 '301': 'no-changed-when', 100 '302': 'deprecated-command-syntax', 101 '303': 'command-instead-of-module', 102 '304': 'inline-env-var', 103 '305': 'command-instead-of-shell', 104 '306': 'risky-shell-pipe', 105 '401': 'git-latest', 106 '402': 'hg-latest', 107 '403': 'package-latest', 108 '404': 'no-relative-paths', 109 '501': 'partial-become', 110 '502': 'unnamed-task', 111 '503': 'no-handler', 112 '504': 'deprecated-local-action', 113 '505': 'missing-import', 114 '601': 'literal-compare', 115 '602': 'empty-string-compare', 116 '701': 'meta-no-info', 117 '702': 'meta-no-tags', 118 '703': 'meta-incorrect', 119 '704': 'meta-video-links', 120 '911': 'syntax-check', 121} 122