CI/CD and Linting¶
Section status: outline
This page is scoped but not yet written in full prose. The sections below define what it will cover.
Why This Exists¶
A playbook that only gets reviewed by a human reading YAML misses a class of mistakes a linter catches in seconds — and a playbook that's never dry-run in CI before a real apply is a production incident waiting for a busy afternoon.
ansible-lint and tox-ansible (for matrix testing across Python/ansible-core versions) both ship together in ansible-dev-tools, so a single install covers most of what this page describes.
What It Will Cover¶
ansible-lint— rule-based playbook/role linting (FQCN usage,command/shelloveruse, missingname:on tasks, deprecated syntax)yamllintfor structural YAML issues underneathansible-lint's Ansible-specific rules- A CI pipeline stage sequence:
yamllint→ansible-lint→ansible-playbook --syntax-check→ansible-playbook --check --diffagainst a real (non-production) inventory → human review → apply - Pinning
requirements.yml/requirements.txtin CI so a run is reproducible, not dependent on whatever happens to resolve that day - A minimal GitHub Actions example running lint +
--checkon every pull request
Common Mistakes¶
- Running
ansible-lintlocally but not enforcing it in CI, so violations creep back in. - No
--check --diffgate before merge, catching logic errors only when they hit a real environment. - CI installing unpinned collections, so a run that passed yesterday fails today for reasons unrelated to the actual change.
Interview Questions¶
- What would a CI pipeline for a playbook repository look like, stage by stage?
- Why pin collection and role versions in CI instead of always installing latest?
Next¶
Continue to Molecule Testing.