Skip to main content

Ansible lint component

Runs ansible-lint for an Ansible project or collection. The component searches from the configured path up to the repository root for ansible.cfg, local sibling collections, Python dependency files, and Ansible requirements.yml or requirements.yaml files. Ansible Galaxy dependencies are installed below .ansible/, which is cached between pipeline runs.

The component tests lint both a nested collection playbook and a project-root playbook that use a local collection role. Separate jobs exercise collection-level and project-level discovery.

Run Ansible lint before committing​

Install pre-commit and Python 3.14, which the pinned hook requires. Then create .pre-commit-config.yaml in the repository root:

---
repos:
- repo: https://github.com/ansible/ansible-lint
rev: v26.9.0
hooks:
- id: ansible-lint

Install the Git hook and check the complete repository:

pre-commit install
pre-commit run --all-files

The hook exits with an error when ansible-lint reports a violation. Pin rev to the release used by your project and update it deliberately.

Inputs​

NameDescriptionDefaultType
------------
allow-failureShould the pipeline continue if linting fails?falseboolean
args-vstring
environmentThe environment name for variables e.g. to unlock secrets.intstring
imageThe image to use for the job.${CI_TOOLS_REPO}/ansible-ee:${CI_TOOLS_COMPONENT_VERSION}string
nameansiblestring
needsThe jobs that this job depends on.[]array
pathAnsible project root.string
rulesThe rules that this job depends on.[{"if":"$CI_PIPELINE_SOURCE == \"schedule\"","when":"never"},{"if":"$CI_PIPELINE_SOURCE == \"merge_request_event\"","when":"always"},{"when":"always"}]array
stageThe pipeline stage that the job will belong to.lintstring