Skip to content

ansible-lint GitHub last commit

ansible-lint documentation

ansible-lint - GitHub

Configuration in MegaLinter

Variable Description Default value
ANSIBLE_ANSIBLE_LINT_ARGUMENTS User custom arguments to add in linter CLI call
Ex: -s --foo "bar"
ANSIBLE_ANSIBLE_LINT_FILE_EXTENSIONS Allowed file extensions. "*" matches any extension, "" matches empty extension. Empty list excludes all files
Ex: [".py", ""]
[".yml", ".yaml"]
ANSIBLE_ANSIBLE_LINT_FILE_NAMES_REGEX File name regex filters. Regular expression list for filtering files by their base names using regex full match. Empty list includes all files
Ex: ["Dockerfile(-.+)?", "Jenkinsfile"]
Include every file
ANSIBLE_ANSIBLE_LINT_PRE_COMMANDS List of bash commands to run before the linter None
ANSIBLE_ANSIBLE_LINT_POST_COMMANDS List of bash commands to run after the linter None
ANSIBLE_ANSIBLE_LINT_CONFIG_FILE ansible-lint configuration file name
Use LINTER_DEFAULT to let the linter find it
.ansible-lint
ANSIBLE_ANSIBLE_LINT_RULES_PATH Path where to find linter configuration file Workspace folder, then MegaLinter default rules
ANSIBLE_ANSIBLE_LINT_DISABLE_ERRORS Run linter but consider errors as warnings false
ANSIBLE_ANSIBLE_LINT_DISABLE_ERRORS_IF_LESS_THAN Maximum number of errors allowed 0
ANSIBLE_DIRECTORY Directory containing ANSIBLE files ansible

MegaLinter Flavours

This linter is available in the following flavours

Flavor Description Embedded linters Info
all Default MegaLinter Flavor 109 Docker Image Size (tag) Docker Pulls
cupcake MegaLinter for the most commonly used languages 79 Docker Image Size (tag) Docker Pulls
documentation MegaLinter for documentation projects 46 Docker Image Size (tag) Docker Pulls
dotnet Optimized for C, C++, C# or VB based projects 56 Docker Image Size (tag) Docker Pulls
go Optimized for GO based projects 49 Docker Image Size (tag) Docker Pulls
java Optimized for JAVA based projects 50 Docker Image Size (tag) Docker Pulls
javascript Optimized for JAVASCRIPT or TYPESCRIPT based projects 55 Docker Image Size (tag) Docker Pulls
php Optimized for PHP based projects 50 Docker Image Size (tag) Docker Pulls
python Optimized for PYTHON based projects 57 Docker Image Size (tag) Docker Pulls
ruby Optimized for RUBY based projects 47 Docker Image Size (tag) Docker Pulls
rust Optimized for RUST based projects 47 Docker Image Size (tag) Docker Pulls
salesforce Optimized for Salesforce based projects 49 Docker Image Size (tag) Docker Pulls
security Optimized for security 21 Docker Image Size (tag) Docker Pulls
swift Optimized for SWIFT based projects 47 Docker Image Size (tag) Docker Pulls
terraform Optimized for TERRAFORM based projects 52 Docker Image Size (tag) Docker Pulls

Behind the scenes

How are identified applicable files

  • Activated only if sub-directory ansible is found. (directory name can be overridden with ANSIBLE_DIRECTORY)
  • File extensions: .yml, .yaml
  • File name do not ends with: vault.yml, vault.yaml, galaxy.yml, galaxy.yaml

How the linting is performed

ansible-lint is called once on the whole project directory (project CLI lint mode)

  • filtering can not be done using MegaLinter configuration variables,it must be done using ansible-lint configuration or ignore file (if existing)
  • VALIDATE_ALL_CODEBASE: false does not make ansible-lint analyze only updated files

Example calls

ansible-lint -v
ansible-lint -v -c .ansible-lint

Help content

usage: ansible-lint [-h] [-L | -T]
                    [-f {rich,plain,md,json,codeclimate,quiet,pep8,sarif,docs}]
                    [-q]
                    [-P [{min,basic,moderate,safety,shared,production} ...]]
                    [-p] [--progressive] [--project-dir PROJECT_DIR]
                    [-r RULESDIR] [-R] [--write [WRITE_LIST]] [--show-relpath]
                    [-t TAGS] [-v] [-x SKIP_LIST] [-w WARN_LIST]
                    [--enable-list ENABLE_LIST] [--nocolor] [--force-color]
                    [--exclude EXCLUDE_PATHS] [-c CONFIG_FILE] [--offline]
                    [--version]
                    [lintables ...]

positional arguments:
  lintables             One or more files or paths. When missing it will
                        enable auto-detection mode.

options:
  -h, --help            show this help message and exit
  -L, --list-rules      List all the rules. For listing rules only the
                        following formats for argument -f are supported:
                        {plain, rich, md}
  -T, --list-tags       List all the tags and the rules they cover. Increase
                        the verbosity level with `-v` to include 'opt-in' tag
                        and its rules.
  -f {rich,plain,md,json,codeclimate,quiet,pep8,sarif,docs}, --format {rich,plain,md,json,codeclimate,quiet,pep8,sarif,docs}
                        stdout formatting, json being an alias for
                        codeclimate. (default: rich)
  -q                    quieter, reduce verbosity, can be specified twice.
  -P [{min,basic,moderate,safety,shared,production} ...], --profile [{min,basic,moderate,safety,shared,production} ...]
                        Specify which rules profile to be used, or displays
                        available profiles when no argument is given.
  -p, --parseable       parseable output, same as '-f pep8'
  --progressive         Return success if it detects a reduction in number of
                        violations compared with previous git commit. This
                        feature works only in git repositories.
  --project-dir PROJECT_DIR
                        Location of project/repository, autodetected based on
                        location of configuration file.
  -r RULESDIR, --rules-dir RULESDIR
                        Specify custom rule directories. Add -R to keep using
                        embedded rules from /venvs/ansible-
                        lint/lib/python3.10/site-packages/ansiblelint/rules
  -R                    Keep default rules when using -r
  --write [WRITE_LIST]  Allow ansible-lint to reformat YAML files and run rule
                        transforms (Reformatting YAML files standardizes
                        spacing, quotes, etc. A rule transform can fix or
                        simplify fixing issues identified by that rule). You
                        can limit the effective rule transforms (the
                        'write_list') by passing a keywords 'all' or 'none' or
                        a comma separated list of rule ids or rule tags. YAML
                        reformatting happens whenever '--write' or '--write='
                        is used. '--write' and '--write=all' are equivalent:
                        they allow all transforms to run. The effective list
                        of transforms comes from 'write_list' in the config
                        file, followed whatever '--write' args are provided on
                        the commandline. '--write=none' resets the list of
                        transforms to allow reformatting YAML without running
                        any of the transforms (ie '--write=none,rule-id' will
                        ignore write_list in the config file and only run the
                        rule-id transform).
  --show-relpath        Display path relative to CWD
  -t TAGS, --tags TAGS  only check rules whose id/tags match these values
  -v                    Increase verbosity level (-vv for more)
  -x SKIP_LIST, --skip-list SKIP_LIST
                        only check rules whose id/tags do not match these
                        values
  -w WARN_LIST, --warn-list WARN_LIST
                        only warn about these rules, unless overridden in
                        config file. Current version default value is:
                        experimental, jinja[spacing], name[casing],
                        name[play], role-name
  --enable-list ENABLE_LIST
                        activate optional rules by their tag name
  --nocolor             disable colored output, same as NO_COLOR=1
  --force-color         Force colored output, same as FORCE_COLOR=1
  --exclude EXCLUDE_PATHS
                        path to directories or files to skip. This option is
                        repeatable.
  -c CONFIG_FILE, --config-file CONFIG_FILE
                        Specify configuration file to use. By default it will
                        look for '.ansible-lint' or '.config/ansible-lint.yml'
  --offline             Disable installation of requirements.yml
  --version

Installation on mega-linter Docker image