Learn any cloudAnsible LearnLabsAnsible syntax check, step by step
Ansible syntax check, step by step
WorkspacesUnknownRun ansible-playbook --syntax-check over the playbook that configures the Hybrid Lab host itself, see it fail until the collections it needs are installed, break a play and read what the check reports, and learn what a syntax check is not — with no host in reach and nothing executed.
Introductoryabout 20 minutesToolsansible
Opening your lab workspace…
Steps
Step 1: Read the layout
The folder is the configuration management for the Hybrid Lab host.
ansible.cfgpoints atinventory/localhost.ymlandroles/;site.ymlruns the roles in order;requirements.ymlpins the collections they use; each role’smeta/argument_specs.ymlis its variable contract. Readsite.ymltop to bottom before running anything.Step 2: Run the syntax check, and watch it fail
ansible-playbook --syntax-check site.ymlThe image carries
ansible-coreand no collections, so the first role that names a module outsideansible.builtinstops the check with "couldn’t resolve module/action". A syntax check resolves every module it meets; a missing collection is a syntax error to it.Step 3: Install the pinned collections
ansible-galaxy collection install -r requirements.yml ansible-playbook --syntax-check site.ymlThe versions are exact, so you install the same code the host runs. The check now ends with
playbook: site.ymland exit code 0.Step 4: Break a play
In
site.yml, renamepre_tasks:topre_taskz:and run the check again. It reports thatpre_taskzis not a valid attribute for a Play, with the file and line. Then open anyroles/*/tasks/main.yml, misspell a module name (ansible.builtin.fil), and see the same kind of message name the task instead. Put both back:git checkout -- . ansible-playbook --syntax-check site.ymlStep 5: What a syntax check is not
It parses and resolves; it does not connect, gather facts, evaluate conditions or run a single module.
--checkmode would need a host to talk to, and a lint (ansible-lint) is a separate tool this image does not carry — run it on your own machine if you want style rules. To see the runner apply the same check to a playbook of your own, send one that usesansible.builtinmodules only, since the runner installs no collections.Checked by the agent (ansible-check): Paste one playbook as the text payload, ansible.builtin modules only: the runner has ansible-core and no collections, so anything else fails to resolve, exactly as step 2 did here.