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
$ git checkout -b your-branch-name
# DO SOME CODING HERE
$ 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.

% DO-NOT-REMOVE-deps-snippet-PLACEHOLDER

Talk to us

Use Github discussions forum or for a live chat experience try #ansible-devtools IRC channel on libera.chat or Matrix room #devtools:ansible.com.

For the full list of Ansible IRC and Mailing list, please see the Ansible Communication page. Release announcements will be made to the Ansible Announce list.

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
ansible-lint==24.2.1.dev13
├── ansible-compat [required: >=4.1.11, installed: 4.1.11]
   ├── ansible-core [required: >=2.12, installed: 2.16.4]
      ├── cryptography [required: Any, installed: 42.0.5]
         └── cffi [required: >=1.12, installed: 1.16.0]
             └── pycparser [required: Any, installed: 2.21]
      ├── Jinja2 [required: >=3.0.0, installed: 3.1.3]
         └── MarkupSafe [required: >=2.0, installed: 2.1.5]
      ├── packaging [required: Any, installed: 23.2]
      ├── PyYAML [required: >=5.1, installed: 6.0.1]
      └── resolvelib [required: >=0.5.3,<1.1.0, installed: 1.0.1]
   ├── jsonschema [required: >=4.6.0, installed: 4.21.1]
      ├── attrs [required: >=22.2.0, installed: 23.2.0]
      ├── jsonschema-specifications [required: >=2023.03.6, installed: 2023.12.1]
         └── referencing [required: >=0.31.0, installed: 0.33.0]
             ├── attrs [required: >=22.2.0, installed: 23.2.0]
             └── rpds-py [required: >=0.7.0, installed: 0.18.0]
      ├── referencing [required: >=0.28.4, installed: 0.33.0]
         ├── attrs [required: >=22.2.0, installed: 23.2.0]
         └── rpds-py [required: >=0.7.0, installed: 0.18.0]
      └── rpds-py [required: >=0.7.1, installed: 0.18.0]
   ├── packaging [required: Any, installed: 23.2]
   ├── PyYAML [required: Any, installed: 6.0.1]
   └── subprocess-tee [required: >=0.4.1, installed: 0.4.1]
├── ansible-core [required: >=2.12.0, installed: 2.16.4]
   ├── cryptography [required: Any, installed: 42.0.5]
      └── cffi [required: >=1.12, installed: 1.16.0]
          └── pycparser [required: Any, installed: 2.21]
   ├── Jinja2 [required: >=3.0.0, installed: 3.1.3]
      └── MarkupSafe [required: >=2.0, installed: 2.1.5]
   ├── packaging [required: Any, installed: 23.2]
   ├── PyYAML [required: >=5.1, installed: 6.0.1]
   └── resolvelib [required: >=0.5.3,<1.1.0, installed: 1.0.1]
├── black [required: >=22.8.0, installed: 24.2.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: 23.2]
   ├── pathspec [required: >=0.9.0, installed: 0.12.1]
   └── platformdirs [required: >=2, installed: 4.2.0]
├── filelock [required: >=3.3.0, installed: 3.13.1]
├── jsonschema [required: >=4.10.0, installed: 4.21.1]
   ├── attrs [required: >=22.2.0, installed: 23.2.0]
   ├── jsonschema-specifications [required: >=2023.03.6, installed: 2023.12.1]
      └── referencing [required: >=0.31.0, installed: 0.33.0]
          ├── attrs [required: >=22.2.0, installed: 23.2.0]
          └── rpds-py [required: >=0.7.0, installed: 0.18.0]
   ├── referencing [required: >=0.28.4, installed: 0.33.0]
      ├── attrs [required: >=22.2.0, installed: 23.2.0]
      └── rpds-py [required: >=0.7.0, installed: 0.18.0]
   └── rpds-py [required: >=0.7.1, installed: 0.18.0]
├── packaging [required: >=21.3, installed: 23.2]
├── pathspec [required: >=0.10.3, installed: 0.12.1]
├── PyYAML [required: >=5.4.1, installed: 6.0.1]
├── rich [required: >=12.0.0, installed: 13.7.1]
   ├── 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.17.2]
├── 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.1]
├── wcmatch [required: >=8.1.2, installed: 8.5.1]
   └── bracex [required: >=2.1.1, installed: 2.4]
└── yamllint [required: >=1.30.0, installed: 1.35.1]
    ├── pathspec [required: >=0.5.3, installed: 0.12.1]
    └── PyYAML [required: Any, installed: 6.0.1]

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: {command}tox -e py -- -k NewRule
  • Run {command}tox in order to run all ansible-lint tests. Adding a new rule can break some other tests. Update them if needed.
  • Run {command}ansible-lint -L and check that the rule description renders correctly.
  • Build the docs using {command}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.