CI — Ansible
Runs ansible-lint and an optional syntax check over a directory of Ansible playbooks/roles. Installs Ansible tooling via pip on the selected Python version.
Usage
yaml
jobs:
ci:
uses: KevinDeBenedetti/github-workflows/.github/workflows/ci-ansible.yml@main
with:
ansible-dir: ansible/
run-syntax-check: trueInputs
| Input | Type | Default | Description |
|---|---|---|---|
ansible-dir | string | ansible/ | Directory containing Ansible playbooks/roles |
ansible-lint-version | string | '' | Deprecated, ignored (warning): ansible-lint comes from a hash-locked requirements file |
ansible-version | string | '' | Deprecated, ignored (warning): ansible comes from a hash-locked requirements file |
python-version | string | '3.12' | Python version to use — 3.12 or newer (the locked tools are resolved for it) |
fail-on-error | boolean | true | Fail the job on lint violations; false runs in advisory mode (warnings) |
run-syntax-check | boolean | false | Run ansible-playbook --syntax-check on matching playbooks |
playbook-glob | string | '*.yml' | Glob (relative to ansible-dir) for playbooks to syntax-check |
runner | string | '"ubuntu-latest"' | Runner labels as JSON — '"ubuntu-latest"' or a label array |
Steps
- Checkout
- Setup Python
- Install ansible-lint from its hash-locked requirements (
setup-ansibleaction,pip --require-hashes) - Run ansible-lint over
ansible-dir(advisory whenfail-on-error: false) - (if
run-syntax-check) Install ansible the same way and runansible-playbook --syntax-checkon each playbook found
Notes
- The
ansible-lintjob always runs; theansible-syntax-checkjob runs only whenrun-syntax-check: true. - The syntax check searches
ansible-dirat depth 1 for files matchingplaybook-glob; if none are found it logs a warning instead of failing. - Matching files that are not playbooks (no play declaring
hosts:/import_playbook:, e.g.requirements.yml,galaxy.yml) are skipped rather than failing the syntax check. - The tools are installed from
.github/actions/setup-ansible/{ansible-lint,ansible}.txt, compiled withuv pip compile --generate-hashes: every package, direct and transitive, is checked against its SHA-256. Renovate bumps the pins and regenerates the locks; the version follows the release of this repository you pin.