Why role quality needs its own step

Ansible is quick to use, which is also a risk. A playbook can look syntactically valid while still being hard to maintain, non-idempotent or unsuitable for CI. A generic Ansible series therefore needs a dedicated quality step.

This article deliberately avoids platform-specific topics. It describes checks that apply equally to Linux baselines, update playbooks, web server roles and later specialist roles.

Minimal validation path

  • Keep YAML and repository structure consistent.

  • Install collections reproducibly.

  • Validate playbooks with --syntax-check.

  • Use ansible-lint as a quality gate.

  • Run check mode and diff mode against lab inventories.

  • Build CI so failures are visible before merge.

Project files for CI

ansible-platform/
requirements.yaml
.ansible-lint
inventories/lab/hosts.yaml
playbooks/linux-baseline.yaml
roles/linux_baseline/

Install collections reproducibly

yaml
# requirements.yaml
collections:
- name: ansible.posix
- name: community.general
bash
ansible-galaxy collection install -r requirements.yaml

Configure ansible-lint

yaml
# .ansible-lint
profile: production
exclude_paths:
- .cache/
- tmp/
warn_list:
- experimental

Local validation commands

bash
ansible-playbook -i inventories/lab/hosts.yaml playbooks/linux-baseline.yaml --syntax-check
ansible-lint playbooks/linux-baseline.yaml roles/linux_baseline
ansible-playbook -i inventories/lab/hosts.yaml playbooks/linux-baseline.yaml --check --diff

Simple CI pipeline

yaml
stages:
- validate
ansible_validate:
stage: validate
image: python:3.13
before_script:
- python -m pip install --upgrade pip
- python -m pip install ansible-core ansible-lint
- ansible-galaxy collection install -r requirements.yaml
script:
- ansible-playbook -i inventories/lab/hosts.yaml playbooks/linux-baseline.yaml --syntax-check
- ansible-lint playbooks/linux-baseline.yaml roles/linux_baseline

What CI does not prove

Linting and syntax checks do not prove that a playbook is operationally correct. They catch common issues early. Real acceptance still needs a lab, check mode, real runs and an idempotence check.

Acceptance table

What comes next

The next part can show how Ansible repositories are versioned, released and changed traceably. That is the bridge between individual playbooks and durable operations.