On this page
The short answerWhat goes stale in Ansible docsExtract the examples firstSyntax-check and list the tasksLint the examplesDry-run with check modeRun it against a throwaway targetTest the copies in your guidesKeep credentials out of the runRun it on every changeChecklist for an Ansible example testWhere DocsAlive fitsWhat this does not replaceThe sources we checkedFAQDocs for infrastructure tools often show Ansible playbooks: an install guide ends with one, a configuration walkthrough is built around one. Modules get renamed, arguments change, collections move, and a playbook that worked last year fails today — usually on a reader's real machine, mid-install. This guide covers the checks that catch that without touching a live server: syntax-check and lint every documented playbook, dry-run it, and then run it for real against a throwaway target.
The short answer
Test an Ansible example in layers, in the order the layers get more expensive. Extract every playbook, inventory and variables file from the docs exactly as printed. Syntax-check each playbook and list its tasks, which proves the file parses and every module it names resolves. Lint the set, which catches the style and naming problems that turn into real failures at upgrade time. Dry-run with check mode against a test inventory to see what the playbook would change. Then run it for real — in a clean container or a disposable VM — because a dry run is a simulation and some tasks can only be judged by running them. Finally, test the copies: the same playbook usually appears in the install guide, the README and a blog post, and each copy ages on its own.
DocsAlive does not parse or lint Ansible content. It reads the pages around the playbooks — the guides and tutorials where the same examples appear as code blocks — and runs those blocks in a fresh container. Keep the Ansible tooling described here for the playbooks themselves, and use an execution check for the pages readers copy from. The GitHub Actions testing guide covers wiring checks like these into CI, and the documentation drift guide covers why the copies drift apart.
What goes stale in Ansible docs
Ansible content ages in predictable places:
- Module names and arguments. A module moved into a collection and now needs its fully qualified name, or an argument was renamed, deprecated or removed. The playbook reads fine and fails at the task that names it.
- Collections and roles. A documented
requirements.ymlentry points at a version that no longer exists, or a role the playbook includes was renamed on Galaxy. - Variables. A variable the playbook needs is not defined in the documented example — it was defined in the author's own inventory, so the example only ever worked on their machine.
- Inventories and host names. The prose tells the reader to run against a group the example inventory never defines.
- Expected output. Sample task output that no longer matches what the current Ansible prints, so readers cannot tell a successful run from a failed one.
Every one of these is visible to a check that costs seconds. The expensive way to find them is a reader, on a production-adjacent machine, following your install guide.
Extract the examples first
The checks below work on files, so the first job is getting every documented example into files, unchanged: each playbook as its own .yml, plus the inventory, group variables and requirements.yml the prose assumes. Keep the page each example came from in the filename or a manifest, so a failure points at the page to fix.
Do not complete the examples as you extract them. Docs playbooks are often fragments — three tasks lifted out of a longer file — and a fragment cannot be syntax-checked as a playbook. That is itself a finding about the page: if the reader cannot run it as printed, the page should say it is a fragment and show where it belongs, or be completed until it runs. Extract what is printed, test what is printed, and fix the page — never quietly fix the test copy, or the suite passes while the docs still fail.
Syntax-check and list the tasks
The cheapest real check is the one Ansible ships. --syntax-check parses the playbook and reports syntax errors without running anything or connecting to a host:
ansible-playbook site.yml --syntax-check
ansible-playbook site.yml --list-tasks
ansible-playbook site.yml --list-hosts
--list-tasks shows the tasks the playbook would run, in order, which proves two things the syntax check alone does not: every role and include the playbook references was found, and the task list matches what the prose says the playbook does. --list-hosts shows which hosts the plays would touch, which catches the inventory mismatch above — a play aimed at a group the documented inventory does not define lists no hosts at all. Run all three against the documented inventory, not your own: the reader only has the documented one.
These checks are fast and need no target machines, so there is no excuse for them to be rarer than every docs change. They will not catch a wrong argument value or a module that moved — that is what lint and the runs below are for.
Lint the examples
Ansible Lint is the command-line tool for linting playbooks, roles and collections, and it catches the class of problem that parses fine today and breaks at the next upgrade:
pip install ansible-lint
ansible-lint site.yml
The rules that matter most for docs examples are the naming ones. The fqcn rule asks for fully qualified collection names — ansible.builtin.copy, not copy — which is exactly the rename that breaks old examples when modules move into collections. name[missing] requires every task to carry a name, which is what makes the sample output in your prose match a real run. no-changed-when flags command and shell tasks that never say when they change something — the tasks that report "changed" on every run and teach readers to ignore the recap.
Lint the examples as their own project, with the lint configuration committed beside them. If a rule genuinely does not apply to a teaching example, skip that one rule in the config with a comment saying why — a blanket skip list trains everyone to ignore the linter, including when it finds the real break.
Dry-run with check mode
Check mode is Ansible's dry run. With --check, Ansible makes no changes on the target hosts: modules that support check mode report what they would change, and --diff alongside it shows the file changes that would result:
ansible-playbook site.yml -i inventory.ini --check --diff
Know its limits, because the official documentation states them plainly: check mode cannot scan all possible resource types and is only a simulation. A module that does not support check mode is skipped, so a playbook can dry-run clean and still fail for real at the skipped task. The command and shell modules are the common case — Ansible cannot predict what an arbitrary command will do, so in check mode they are skipped unless the task gives them creates or removes to predict from. Tasks later in the playbook may also behave differently in a dry run, because an earlier task that a later one depends on never actually ran.
Used with those limits in mind, check mode is the right middle layer: it proves the playbook connects, gathers facts, evaluates its conditions and reaches the end, and its diff output is the fastest way to see whether the changes match the prose. It is a preview, not a proof — which is why there is one more layer.
Run it against a throwaway target
The only complete test of a playbook is a run. Give it a target that cannot matter: a clean container or a disposable VM, built from the same operating system the docs name, with nothing on it the run could damage. Run the documented playbook, with the documented inventory and variables, from the beginning, as a reader would. Then run it a second time. A playbook that changes things on the second run is not idempotent, and readers will run it twice — the second run is where undocumented assumptions surface.
For roles and collections, this layer has a dedicated tool. Molecule is the test framework for Ansible content: molecule test runs the full sequence — create the instance, converge it with the role, run the role again to prove idempotence, verify the result, and destroy the instance. If your docs ship a role, its examples belong in a Molecule scenario, and the idempotence step alone catches the missing changed_when class of problem that lint can only warn about.
Compare the run's recap and key task output with the expected output printed in the docs. When they disagree, one of them is wrong, and it is usually the docs.
Test the copies in your guides
A playbook rarely lives in one place. The install guide shows the full file, the quickstart shows the first three tasks, the README shows a shortened version with different variables, and a launch post froze another copy in time. A module rename breaks all of them, but a fix usually lands in one.
Extract from every page, not just the canonical one — the extraction step does not care which page a block came from. When a copy fails, fix the page and search the rest of the docs for the same task text before you call it done. The README testing guide covers the copy that readers meet first and maintainers re-check last.
Keep credentials out of the run
Infrastructure examples attract real secrets like no other docs genre: vault passwords, cloud keys, become passwords, all helpfully illustrated. Three rules keep the test lane safe. First, the syntax, lint and check-mode layers need no real credentials — run them in the plainest CI job you have. Second, the real run uses a throwaway target with throwaway credentials, created for the test and destroyed with it; a playbook that needs a production credential to test is a playbook whose example is wrong for docs. Third, scan the examples themselves: if a documented playbook contains a real-looking password, token or private key, that is a finding about the page, and it should fail the run like any other error.
Run it on every change
- Pull requests: syntax-check, list tasks and lint on every change to the docs or the examples. All three are fast and need no targets.
- Releases: add the check-mode run and the full throwaway-target run, against the Ansible and collection versions the release notes name, before the docs are announced.
- Nightly: run the full set even when nobody touched the docs. Collections release on their own schedule, and the nightly run is what catches a documented
requirements.ymlentry the day it stops resolving.
Pin the Ansible version in the test job and record it with the results. "The example fails" means one thing on the version your docs claim to support and something else entirely on a version nobody promised — the run should say which it used.
Checklist for an Ansible example test
- Every playbook, inventory, variables file and requirements file extracted from the docs, unchanged, with its source page recorded.
--syntax-checkpasses on every documented playbook.--list-tasksoutput matches the tasks the prose describes;--list-hostsmatches the documented inventory.- Ansible Lint passes, with any skipped rules named in the config with a reason.
- Modules named by their fully qualified collection names.
- Check-mode run with
--diffcompletes, and its predicted changes match the prose. - Full run against a throwaway target passes — twice, with no changes on the second run.
- Roles and collections covered by a Molecule scenario where they are shipped.
- Expected output in the docs compared with a real run's output.
- Copies in quickstarts, READMEs and posts extracted and tested too.
- No real credentials in any example; test targets use throwaway credentials.
Where DocsAlive fits
The checks above cover the playbooks. They do not cover the pages around them — the install guide whose prose walks through the playbook task by task, the tutorial that builds it up over three pages, the README in every role repository. Those pages are Markdown, and their code blocks are where readers actually copy from. DocsAlive runs the code samples in your docs in a clean sandbox and reports what breaks: it installs DocsAlive as a GitHub App, runs the blocks, and opens fix PRs that a human approves. A free health check runs the samples on up to 40 pages of a public repo and sends a report within 2 business days — the quickest way to see where the copies in your guides stand. The docs testing checklist puts this execution layer next to the rest of the pre-release checks.
What this does not replace
Testing the examples does not test your infrastructure: whether the playbook configures the service correctly, securely and at scale is a question for your own environment testing, and a playbook can pass every check here and still be the wrong playbook to teach. Lint does not replace a run, and a dry run does not replace a real run on a throwaway target. And none of this checks the prose — a guide can ship perfectly tested playbooks and still explain them badly. What these checks remove is the specific, common failure where the docs hand a reader a playbook that cannot run, and they remove it before the reader's machine does.
The sources we checked
| Source | What it covers |
|---|---|
| Ansible documentation | The ansible-playbook options: --syntax-check, --list-tasks, --list-hosts, and check mode with --diff, including its stated limits |
| Ansible Lint documentation | What it lints — playbooks, roles and collections — and the fqcn, name and no-changed-when rules |
| Molecule documentation | The molecule test sequence: create, converge, idempotence, verify, destroy |
| DocsAlive product pages | What the health check runs, the GitHub App, and human-approved fix PRs |
FAQ
Is a syntax check enough?
No. A syntax check proves the file parses. It does not prove the modules resolve, the variables exist, or the playbook changes what the prose says. Each layer above catches failures the cheaper layers cannot see, and the full run on a throwaway target is the only complete test.
Why not just use check mode?
Because check mode is a simulation by design. Modules without check-mode support are skipped, command and shell tasks cannot be predicted without help, and later tasks may behave differently when earlier ones never ran. Check mode is a strong preview and a weak proof.
Our examples are fragments of a larger playbook. How do we test them?
Either complete them until each one runs as printed — the reader's experience — or assemble the fragments into the full playbook they came from and test that, while making the page say plainly that the blocks are fragments. What does not work is testing a completed version the reader never sees.




