|
| 1 | +[id="devtools-ansible-lint-customize_{context}"] |
| 2 | + |
| 3 | += Customizing {LintName} |
| 4 | + |
| 5 | +You can customize how {LintName} runs against automation content to suit your needs. |
| 6 | +You can ignore certain rules, enable opt-in rules, and control various other settings. |
| 7 | + |
| 8 | +{LintName} loads configuration from the `.ansible-lint.yml` configuration file, or from a file that you specify in the command line. |
| 9 | +This file is not scaffolded when you create a playbook or collection project. |
| 10 | +You must create the file in the `.config` directory of your {VSCode} workspace. |
| 11 | + |
| 12 | +Any configuration option that is passed from the command line will override the one specified inside the configuration file. |
| 13 | + |
| 14 | +The example `.ansible-lint.yml` file below selects the `production` profile. |
| 15 | +The settings are explained in the comments. |
| 16 | + |
| 17 | +---- |
| 18 | +--- |
| 19 | +# .ansible-lint |
| 20 | +
|
| 21 | +profile: production # min, basic, moderate,safety, shared, production, null |
| 22 | +
|
| 23 | +# Allows dumping of results in SARIF format |
| 24 | +# sarif_file: result.sarif |
| 25 | +
|
| 26 | +# exclude_paths included in this file are parsed relative to this file's location |
| 27 | +# and not relative to the CWD of execution. CLI arguments passed to the --exclude |
| 28 | +# option are parsed relative to the CWD of execution. |
| 29 | +exclude_paths: |
| 30 | + - .cache/ # implicit unless exclude_paths is defined in config |
| 31 | + - test/fixtures/formatting-before/ |
| 32 | + - test/fixtures/formatting-prettier/ |
| 33 | +# parseable: true |
| 34 | +# quiet: true |
| 35 | +# strict: true |
| 36 | +# verbosity: 1 |
| 37 | +
|
| 38 | +# Mock modules or roles in order to pass ansible-playbook --syntax-check |
| 39 | +mock_modules: |
| 40 | + - zuul_return |
| 41 | + # note the foo.bar is invalid as being neither a module or a collection |
| 42 | + - fake_namespace.fake_collection.fake_module |
| 43 | + - fake_namespace.fake_collection.fake_module.fake_submodule |
| 44 | +mock_roles: |
| 45 | + - mocked_role |
| 46 | + - author.role_name # old standalone galaxy role |
| 47 | + - fake_namespace.fake_collection.fake_role # role within a collection |
| 48 | +
|
| 49 | +# Enable checking of loop variable prefixes in roles |
| 50 | +loop_var_prefix: "^(__|{role}_)" |
| 51 | +
|
| 52 | +# Enforce variable names to follow pattern below, in addition to Ansible own |
| 53 | +# requirements, like avoiding python identifiers. To disable add `var-naming` |
| 54 | +# to skip_list. |
| 55 | +var_naming_pattern: "^[a-z_][a-z0-9_]*$" |
| 56 | +
|
| 57 | +use_default_rules: true |
| 58 | +# Load custom rules from this specific folder |
| 59 | +# rulesdir: |
| 60 | +# - ./rule/directory/ |
| 61 | +
|
| 62 | +# Ansible-lint is able to recognize and load skip rules stored inside |
| 63 | +# `.ansible-lint-ignore` (or `.config/ansible-lint-ignore.txt`) files. |
| 64 | +# To skip a rule just enter filename and tag, like "playbook.yml package-latest" |
| 65 | +# on a new line. |
| 66 | +# Optionally you can add comments after the tag, prefixed by "#". |
| 67 | +# When putting ignores inside the ignore file, they are marked as ignored, but |
| 68 | +# still visible, making it easier to address later. |
| 69 | +
|
| 70 | +# Ansible-lint does not automatically load rules that have the 'opt-in' tag. |
| 71 | +# You must enable opt-in rules by listing each rule 'id' below. |
| 72 | +enable_list: |
| 73 | + - args |
| 74 | + - empty-string-compare # opt-in |
| 75 | + - no-log-password # opt-in |
| 76 | + - no-same-owner # opt-in |
| 77 | + - name[prefix] # opt-in |
| 78 | + - galaxy-version-incorrect # opt-in |
| 79 | + # add yaml here if you want to avoid ignoring yaml checks when yamllint |
| 80 | + # library is missing. Normally its absence just skips using that rule. |
| 81 | + - yaml |
| 82 | +# Report only a subset of tags and fully ignore any others |
| 83 | +# tags: |
| 84 | +# - jinja[spacing] |
| 85 | +
|
| 86 | +# Ansible-lint does not fail on warnings from the rules or tags listed below |
| 87 | +warn_list: |
| 88 | + - skip_this_tag |
| 89 | + - experimental # experimental is included in the implicit list |
| 90 | + # - role-name |
| 91 | + # - yaml[document-start] # you can also use sub-rule matches |
| 92 | +
|
| 93 | +# Some rules can transform files to fix (or make it easier to fix) identified |
| 94 | +# errors. `ansible-lint --fix` will reformat YAML files and run these transforms. |
| 95 | +# By default it will run all transforms (effectively `write_list: ["all"]`). |
| 96 | +# You can disable running transforms by setting `write_list: ["none"]`. |
| 97 | +# Or only enable a subset of rule transforms by listing rules/tags here. |
| 98 | +# write_list: |
| 99 | +# - all |
| 100 | +
|
| 101 | +# Offline mode disables installation of requirements.yml and schema refreshing |
| 102 | +offline: true |
| 103 | +
|
| 104 | +# Define required Ansible's variables to satisfy syntax check |
| 105 | +extra_vars: |
| 106 | + foo: bar |
| 107 | + multiline_string_variable: | |
| 108 | + line1 |
| 109 | + line2 |
| 110 | + complex_variable: ":{;\t$()" |
| 111 | +
|
| 112 | +# Uncomment to enforce action validation with tasks, usually is not |
| 113 | +# needed as Ansible syntax check also covers it. |
| 114 | +# skip_action_validation: false |
| 115 | +
|
| 116 | +# List of additional kind:pattern to be added at the top of the default |
| 117 | +# match list, first match determines the file kind. |
| 118 | +kinds: |
| 119 | + # - playbook: "**/examples/*.{yml,yaml}" |
| 120 | + # - galaxy: "**/folder/galaxy.yml" |
| 121 | + # - tasks: "**/tasks/*.yml" |
| 122 | + # - vars: "**/vars/*.yml" |
| 123 | + # - meta: "**/meta/main.yml" |
| 124 | + - yaml: "**/*.yaml-too" |
| 125 | +
|
| 126 | +# List of additional collections to allow in only-builtins rule. |
| 127 | +# only_builtins_allow_collections: |
| 128 | +# - example_ns.example_collection |
| 129 | +
|
| 130 | +# List of additions modules to allow in only-builtins rule. |
| 131 | +# only_builtins_allow_modules: |
| 132 | +# - example_module |
| 133 | +
|
| 134 | +# Allow setting custom prefix for name[prefix] rule |
| 135 | +task_name_prefix: "{stem} | " |
| 136 | +# Complexity related settings |
| 137 | +
|
| 138 | +# Limit the depth of the nested blocks: |
| 139 | +# max_block_depth: 20 |
| 140 | +---- |
| 141 | + |
| 142 | +The following example `.ansible-lint.yml` file excludes the comments. |
| 143 | +It selects the `production` profile and enables fixing of files. |
| 144 | + |
| 145 | +---- |
| 146 | +--- |
| 147 | +profile: 'production' |
| 148 | +
|
| 149 | +loop_var_prefix: '^(__|{role}_)' |
| 150 | +var_naming_pattern: '^[a-z_][a-z0-9_]*$' |
| 151 | +use_default_rules: true |
| 152 | +offline: true |
| 153 | +skip_action_validation: false |
| 154 | +
|
| 155 | +kinds: |
| 156 | + - tasks: 'tasks/*.{yml,yaml}' |
| 157 | + - vars: 'vars/*.{yml,yaml}' |
| 158 | + - vars: 'defaults/*.{yml,yaml}' |
| 159 | + - meta: 'meta/main.{yml,yaml}' |
| 160 | + - yaml: '.ansible-lint' |
| 161 | + - yaml: '.github/workflows/*.{yml,yaml}' |
| 162 | + - yaml: '.pre-commit-config.yaml' |
| 163 | + - yaml: '.yamllint' |
| 164 | + - yaml: 'collections/requirements.yml' |
| 165 | +
|
| 166 | +task_name_prefix: '{stem} | ' |
| 167 | +
|
| 168 | +exclude_paths: |
| 169 | + - '.git/' |
| 170 | + - 'files/' |
| 171 | +
|
| 172 | +max_block_depth: 20 |
| 173 | +skip_list: [] |
| 174 | +warn_list: |
| 175 | + - 'experimental' |
| 176 | +write_list: |
| 177 | + - 'all' |
| 178 | +---- |
| 179 | + |
| 180 | +To specify the configuration file, use the `-c <filename>` CLI flag with command line invocations of `{LintCmd}`: |
| 181 | + |
| 182 | +---- |
| 183 | +ansible-lint -c path/to/ansible-lint-dev.yml |
| 184 | +---- |
| 185 | + |
0 commit comments