Skip to content

ansible-lint

ansible-lint documentation

ansible-lint - GitHub

Configuration in Mega-Linter

Variable Description Default value
ANSIBLE_ANSIBLE_LINT_ARGUMENTS User custom arguments to add in linter CLI call
Ex: -s --foo "bar"
ANSIBLE_ANSIBLE_LINT_FILTER_REGEX_INCLUDE Custom regex including filter
Ex: (src|lib)
Include every file
ANSIBLE_ANSIBLE_LINT_FILTER_REGEX_EXCLUDE Custom regex excluding filter
Ex: (test|examples)
Exclude no file
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_CONFIG_FILE ansible-lint configuration file name
Use LINTER_DEFAULT to let the linter find it
.ansible-lint.yml
ANSIBLE_ANSIBLE_LINT_RULES_PATH Path where to find linter configuration file Workspace folder, then Mega-Linter default rules
ANSIBLE_ANSIBLE_LINT_DISABLE_ERRORS Run linter but consider errors as warnings false
ANSIBLE_DIRECTORY Directory containing ANSIBLE files ansible

Mega-Linter Flavours

This linter is available in the following flavours

Flavor Description Embedded linters Info
all Default Mega-Linter Flavor 83 Docker Image Size (tag) Docker Pulls
dart Optimized for DART based projects 37 Docker Image Size (tag) Docker Pulls
documentation Mega-Linter for documentation projects 36 Docker Image Size (tag) Docker Pulls
dotnet Optimized for C, C++, C# or VB based projects 42 Docker Image Size (tag) Docker Pulls
go Optimized for GO based projects 38 Docker Image Size (tag) Docker Pulls
java Optimized for JAVA based projects 37 Docker Image Size (tag) Docker Pulls
javascript Optimized for JAVASCRIPT or TYPESCRIPT based projects 45 Docker Image Size (tag) Docker Pulls
php Optimized for PHP based projects 40 Docker Image Size (tag) Docker Pulls
python Optimized for PYTHON based projects 43 Docker Image Size (tag) Docker Pulls
ruby Optimized for RUBY based projects 37 Docker Image Size (tag) Docker Pulls
rust Optimized for RUST based projects 37 Docker Image Size (tag) Docker Pulls
salesforce Optimized for Salesforce based projects 37 Docker Image Size (tag) Docker Pulls
scala Optimized for SCALA based projects 37 Docker Image Size (tag) Docker Pulls
swift Optimized for SWIFT based projects 37 Docker Image Size (tag) Docker Pulls
terraform Optimized for TERRAFORM based projects 39 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

Example calls

ansible-lint -v myfile.yml
ansible-lint -v -c .ansible-lint.yml myfile.yml

Help content

Usage: ansible-lint [options] [playbook.yml [playbook2 ...]]

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -L                    list all the rules
  -q                    quieter, although not silent output
  -p                    parseable output in the format of pep8
  --parseable-severity  parseable output including severity of rule
  -r RULESDIR           specify one or more rules directories using one or
                        more -r arguments. Any -r flags override the default
                        rules in /usr/lib/python3.8/site-
                        packages/ansiblelint/rules, unless -R is also used.
  -R                    Use default rules in /usr/lib/python3.8/site-
                        packages/ansiblelint/rules in addition to any extra
                        rules directories specified with -r. There is no need
                        to specify this if no -r flags are used
  -t TAGS               only check rules whose id/tags match these values
  -T                    list all the tags
  -v                    Increase verbosity level
  -x SKIP_LIST          only check rules whose id/tags do not match these
                        values
  --nocolor             disable colored output
  --force-color         Try force colored output (relying on ansible's code)
  --exclude=EXCLUDE_PATHS
                        path to directories or files to skip. This option is
                        repeatable.
  -c C                  Specify configuration file to use.  Defaults to
                        ".ansible-lint"

Installation on mega-linter Docker image

Example success log

Results of ansible-lint linter (version 4.2.0)
See documentation on https://nvuillam.github.io/mega-linter/descriptors/ansible_ansible_lint/
-----------------------------------------------

[SUCCESS] .automation/test/ansible/ansible/ansible_good_1.yml
    Examining .automation/test/ansible/ansible/ansible_good_1.yml of type playbook
    Examining .automation/test/ansible/ansible/ghe-initialize/tasks/ghe-api-config-apply.yml of type tasks
    Examining .automation/test/ansible/ansible/ghe-initialize/tasks/ghe-config-apply.yml of type tasks
    Examining .automation/test/ansible/ansible/ghe-initialize/tasks/collectd-settings.yml of type tasks
    Examining .automation/test/ansible/ansible/ghe-initialize/tasks/ghe-ldap-configuration.yml of type tasks
    Examining .automation/test/ansible/ansible/ghe-initialize/tasks/splunk-settings.yml of type tasks
    Examining .automation/test/ansible/ansible/ghe-initialize/tasks/main.yml of type tasks
    Examining .automation/test/ansible/ansible/ghe-initialize/tasks/ghe-initial-configuration.yml of type tasks
    Examining .automation/test/ansible/ansible/ghe-initialize/handlers/main.yml of type handlers

Example error log

Results of ansible-lint linter (version 4.2.0)
See documentation on https://nvuillam.github.io/mega-linter/descriptors/ansible_ansible_lint/
-----------------------------------------------

[ERROR] .automation/test/ansible/ansible/ansible_bad_1.yml
    Traceback (most recent call last):
      File "/usr/bin/ansible-lint", line 11, in <module>
        load_entry_point('ansible-lint==4.2.0', 'console_scripts', 'ansible-lint')()
      File "/usr/lib/python3.8/site-packages/ansiblelint/__main__.py", line 187, in main
        matches.extend(runner.run())
      File "/usr/lib/python3.8/site-packages/ansiblelint/__init__.py", line 267, in run
        for child in ansiblelint.utils.find_children(arg, self.playbook_dir):
      File "/usr/lib/python3.8/site-packages/ansiblelint/utils.py", line 163, in find_children
        for child in play_children(basedir, item, playbook[1], playbook_dir):
      File "/usr/lib/python3.8/site-packages/ansiblelint/utils.py", line 215, in play_children
        return delegate_map[k](basedir, k, v, parent_type)
      File "/usr/lib/python3.8/site-packages/ansiblelint/utils.py", line 246, in _taskshandlers_children
        results.extend(_roles_children(basedir, k, [th['action'].get('name')],
      File "/usr/lib/python3.8/site-packages/ansiblelint/utils.py", line 285, in _roles_children
        results.extend(_look_for_role_files(basedir, role, main=main))
      File "/usr/lib/python3.8/site-packages/ansiblelint/utils.py", line 330, in _look_for_role_files
        role_path = _rolepath(basedir, role)
      File "/usr/lib/python3.8/site-packages/ansiblelint/utils.py", line 299, in _rolepath
        path_dwim(basedir, os.path.join('roles', role)),
      File "/usr/lib/python3.8/posixpath.py", line 90, in join
        genericpath._check_arg_types('join', a, *p)
      File "/usr/lib/python3.8/genericpath.py", line 152, in _check_arg_types
        raise TypeError(f'{funcname}() argument must be str, bytes, or '
    TypeError: join() argument must be str, bytes, or os.PathLike object, not 'NoneType'