Skip to main content
Ansible-lint is a static analysis tool that reviews your Ansible playbooks, roles, and collections to surface errors, stylistic issues, and potentially dangerous constructs before they run. Think of it as an automated, consistent code reviewer that enforces best practices across your automation repository. You may already use Ansible’s --check (check mode) and --diff to preview changes without applying them — those help verify what changes would happen. Ansible-lint complements that by verifying how the playbooks are written, helping keep them readable, consistent, and maintainable as projects grow.
A split slide: an orange left panel reads "DevOps at a Busy Company" with a circular avatar. The white right panel is titled "Automating with Ansible for a while now" and shows boxes for YAML files (site.yml, webservers.yml, patching.yml, deploy.yml, databases.yml, backup.yml) plus a "Complexity Grows With It" badge.
What ansible-lint does
  • Scans playbooks, roles, and collections for common mistakes and style inconsistencies.
  • Reports rule violations with file and line numbers, plus an identifying tag (e.g. name[casing]) so you know what to fix.
  • Can be run locally, in pre-commit hooks, or as part of CI pipelines to enforce standards automatically.
More: ansible-lint documentation
A purple-gradient slide reading "A seasoned Ansible mentor sitting beside you," showing an Ansible-lint logo and a user avatar with chat bubbles saying "Spotted a problem here" and "Here's what you missed."
Example: find style issues quickly Consider a sample playbook style-example.yml that installs and configures NGINX but intentionally includes a few style problems:
  • Inconsistent indentation (some tasks use two spaces, one uses four).
  • Inconsistent or missing task name fields (mixed case and some unnamed tasks).
  • Using the shell module where command or a dedicated module would be safer and faster.
Run ansible-lint and it will list problems with file names and line numbers:
Each message ends with a rule tag (for example name[casing]), and the output points to the offending line. Common rules you’ll see include task naming rules, YAML indentation issues, and warnings about unnecessary shell usage — when shell features (like pipes or expansions) aren’t required, prefer command or a specialised module.
A presentation slide titled "Shell, or Command" showing a card with an orange "shell" badge, the heading "Only When You Truly Need It," and a bullet point saying "Slower than the command module." A small KodeKloud logo is visible in the bottom-left.
Quick note on exit codes
  • If ansible-lint prints nothing and exits with code 0, it found no issues:
  • Non-zero exit codes indicate one or more linting failures — useful for failing CI jobs or blocking merges when used in automation.
Common ansible-lint rules (examples) Integrating ansible-lint into your workflow
  • Run it locally during development to catch issues early.
  • Add it to pre-commit hooks so every commit is checked automatically.
  • Include it in CI pipelines so pull requests are validated before merging.
Integrate ansible-lint into pre-commit hooks or CI jobs so lint failures block merges until issues are resolved. This enforces consistent style and prevents regressions across the team.
Benefits
  • Prevents style and correctness regressions in large automation codebases.
  • Saves time by turning ad-hoc reviews into automated checks.
  • Improves maintainability and readability of playbooks, roles, and collections.
A clean slide titled "A Review on Every Change" showing four numbered steps: 01 Commit a Change, 02 CI Picks It Up, 03 Ansible-lint Reviews, and 04 Merge, each with a short explanatory line. The layout emphasizes an automated CI review workflow for code changes.
Links and references By making ansible-lint a routine part of development and CI, you get an automated, consistent “mentor” for your Ansible codebase — catching issues early and keeping automation reliable and maintainable as it scales.

Watch Video

Practice Lab