Skip to content

Contributing to Ansible-lint

To contribute to ansible-lint, please use pull requests on a branch of your own fork.

After creating your fork on GitHub, you can do:

$ git clone --recursive git@github.com:your-name/ansible-lint
$ cd ansible-lint
$ # Recommended: Initialize and activate a Python virtual environment
$ pip install --upgrade pip
$ pip install -e '.[test]'       # Install testing dependencies
$ tox run -e lint,pkg,docs,py  # Ensure subset of tox tests work in clean checkout
$ git checkout -b your-branch-name
# DO SOME CODING HERE
$ tox run -e lint,pkg,docs,py  # Ensure subset of tox tests work with your changes
$ git add your new files
$ git commit -v
$ git push origin your-branch-name

You will then be able to create a pull request from your commit.

All fixes to core functionality (i.e. anything except docs or examples) should be accompanied by tests that fail prior to your change and succeed afterwards.

Feel free to raise issues in the repo if you feel unable to contribute a code fix.

Standards

ansible-lint works only with supported Ansible versions at the time it was released.

Automated tests will be run against all PRs, to run checks locally before pushing commits, just use tox.

Talk to us

Connect with the Ansible community!

Join the Ansible forum to ask questions, get help, and interact with the community.

  • Get Help: get help or help others. Please add appropriate tags if you start new discussions, for example use the ansible-lint or devtools tags.
  • Social Spaces: meet and interact with fellow enthusiasts.
  • News & Announcements: track project-wide announcements including social events.

To get release announcements and important changes from the community, see the Bullhorn newsletter.

For a live chat experience join the #devtools:ansible.com Matrix room.

You can find more information in the Ansible communication guide.

Possible security bugs should be reported via email to security@ansible.com.

Code of Conduct

As with all Ansible projects, we have a Code of Conduct.

Module dependency graph

Extra care should be taken when considering adding any dependency. Removing most dependencies on Ansible internals is desired as these can change without any warning.

_PIP_USE_IMPORTLIB_METADATA=0 pipdeptree -p ansible-lint
Warning!!! Duplicate package metadata found:
"/home/docs/checkouts/readthedocs.org/user_builds/ansible-lint/checkouts/latest/src"
  ansible-lint                     24.9.3.dev4      (using 24.9.3.dev4, "/home/docs/checkouts/readthedocs.org/user_builds/ansible-lint/checkouts/latest/.tox/docs/lib/python3.11/site-packages")
NOTE: This warning isn't a failure warning.
------------------------------------------------------------------------
ansible-lint==24.9.3.dev4
├── ansible-compat [required: >=24.9.1, installed: 24.9.1]
   ├── ansible-core [required: >=2.14, installed: 2.17.5]
      ├── cryptography [required: Any, installed: 43.0.1]
         └── cffi [required: >=1.12, installed: 1.17.1]
             └── pycparser [required: Any, installed: 2.22]
      ├── Jinja2 [required: >=3.0.0, installed: 3.1.4]
         └── MarkupSafe [required: >=2.0, installed: 3.0.1]
      ├── packaging [required: Any, installed: 24.1]
      ├── PyYAML [required: >=5.1, installed: 6.0.2]
      └── resolvelib [required: >=0.5.3,<1.1.0, installed: 1.0.1]
   ├── jsonschema [required: >=4.6.0, installed: 4.23.0]
      ├── attrs [required: >=22.2.0, installed: 24.2.0]
      ├── jsonschema-specifications [required: >=2023.03.6, installed: 2024.10.1]
         └── referencing [required: >=0.31.0, installed: 0.35.1]
             ├── attrs [required: >=22.2.0, installed: 24.2.0]
             └── rpds-py [required: >=0.7.0, installed: 0.20.0]
      ├── referencing [required: >=0.28.4, installed: 0.35.1]
         ├── attrs [required: >=22.2.0, installed: 24.2.0]
         └── rpds-py [required: >=0.7.0, installed: 0.20.0]
      └── rpds-py [required: >=0.7.1, installed: 0.20.0]
   ├── packaging [required: Any, installed: 24.1]
   ├── PyYAML [required: Any, installed: 6.0.2]
   └── subprocess-tee [required: >=0.4.1, installed: 0.4.2]
├── ansible-core [required: >=2.13.0, installed: 2.17.5]
   ├── cryptography [required: Any, installed: 43.0.1]
      └── cffi [required: >=1.12, installed: 1.17.1]
          └── pycparser [required: Any, installed: 2.22]
   ├── Jinja2 [required: >=3.0.0, installed: 3.1.4]
      └── MarkupSafe [required: >=2.0, installed: 3.0.1]
   ├── packaging [required: Any, installed: 24.1]
   ├── PyYAML [required: >=5.1, installed: 6.0.2]
   └── resolvelib [required: >=0.5.3,<1.1.0, installed: 1.0.1]
├── black [required: >=24.3.0, installed: 24.10.0]
   ├── click [required: >=8.0.0, installed: 8.1.7]
   ├── mypy-extensions [required: >=0.4.3, installed: 1.0.0]
   ├── packaging [required: >=22.0, installed: 24.1]
   ├── pathspec [required: >=0.9.0, installed: 0.12.1]
   └── platformdirs [required: >=2, installed: 4.3.6]
├── filelock [required: >=3.3.0, installed: 3.16.1]
├── importlib_metadata [required: Any, installed: 8.5.0]
   └── zipp [required: >=3.20, installed: 3.20.2]
├── jsonschema [required: >=4.10.0, installed: 4.23.0]
   ├── attrs [required: >=22.2.0, installed: 24.2.0]
   ├── jsonschema-specifications [required: >=2023.03.6, installed: 2024.10.1]
      └── referencing [required: >=0.31.0, installed: 0.35.1]
          ├── attrs [required: >=22.2.0, installed: 24.2.0]
          └── rpds-py [required: >=0.7.0, installed: 0.20.0]
   ├── referencing [required: >=0.28.4, installed: 0.35.1]
      ├── attrs [required: >=22.2.0, installed: 24.2.0]
      └── rpds-py [required: >=0.7.0, installed: 0.20.0]
   └── rpds-py [required: >=0.7.1, installed: 0.20.0]
├── packaging [required: >=21.3, installed: 24.1]
├── pathspec [required: >=0.10.3, installed: 0.12.1]
├── PyYAML [required: >=5.4.1, installed: 6.0.2]
├── rich [required: >=12.0.0, installed: 13.9.2]
   ├── markdown-it-py [required: >=2.2.0, installed: 3.0.0]
      └── mdurl [required: ~=0.1, installed: 0.1.2]
   └── Pygments [required: >=2.13.0,<3.0.0, installed: 2.18.0]
├── ruamel.yaml [required: >=0.18.5, installed: 0.18.6]
   └── ruamel.yaml.clib [required: >=0.2.7, installed: 0.2.8]
├── subprocess-tee [required: >=0.4.1, installed: 0.4.2]
├── wcmatch [required: >=8.1.2, installed: 10.0]
   └── bracex [required: >=2.1.1, installed: 2.5.post1]
└── yamllint [required: >=1.30.0, installed: 1.35.1]
    ├── pathspec [required: >=0.5.3, installed: 0.12.1]
    └── PyYAML [required: Any, installed: 6.0.2]

Adding a new rule

Writing a new rule is as easy as adding a single new rule, one that combines implementation, testing and documentation.

One good example is MetaTagValidRule which can easily be copied in order to create a new rule by following the steps below:

  • Use a short but clear class name, which must match the filename
  • Pick an unused id, the first number is used to determine rule section. Look at rules page and pick one that matches the best your new rule and ee which one fits best.
  • Include experimental tag. Any new rule must stay as experimental for at least two weeks until this tag is removed in next major release.
  • Update all class level variables.
  • Implement linting methods needed by your rule, these are those starting with match prefix. Implement only those you need. For the moment you will need to look at how similar rules were implemented to figure out what to do.
  • Update the tests. It must have at least one test and likely also a negative match one.
  • If the rule is task specific, it may be best to include a test to verify its use inside blocks as well.
  • Optionally run only the rule specific tests with a command like: tox -e py -- -k NewRule
  • Run tox in order to run all ansible-lint tests. Adding a new rule can break some other tests. Update them if needed.
  • Run ansible-lint -L and check that the rule description renders correctly.
  • Build the docs using tox -e docs and check that the new rule is displayed correctly in them.

Documentation changes

To build the docs, run tox -e docs. At the end of the build, you will see the local location of your built docs.

Building docs locally may not be identical to CI/CD builds. We recommend you to create a draft PR and check the RTD PR preview page too.

If you do not want to learn the reStructuredText format, you can also file an issue, and let us know how we can improve our documentation.