Interview Prep/Ansible/Testing, CI/CD and Quality

How do you set up pre-commit hooks for an Ansible repo?

BeginnerProductionTesting, CI/CD and Quality
Answer

Pre-commit runs the cheap checks before code ever reaches CI, so reviews focus on design instead of indentation.

# .pre-commit-config.yaml
repos:
  - repo: https://github.com/adrienverge/yamllint
    rev: v1.35.1
    hooks:
      - id: yamllint
  - repo: https://github.com/ansible/ansible-lint
    rev: v25.1.3
    hooks:
      - id: ansible-lint
  - repo: https://github.com/gitleaks/gitleaks
    rev: v8.21.2
    hooks:
      - id: gitleaks
pip install pre-commit
pre-commit install            # hook into git commit
pre-commit run --all-files    # first full run
pre-commit autoupdate         # bump pinned revs deliberately

CI runs pre-commit run --all-files too, because hooks on laptops can be skipped with --no-verify.

All Ansible questions Roadmap: Ansible

More on Testing, CI/CD and Quality