Ansible "Syntax Error while loading YAML" in CI
The YAML parser could not load a playbook or vars file. Indentation, an unquoted value containing a colon, or a leading Jinja brace are the usual culprits.
What this error means
ansible-playbook (or --syntax-check) fails with "Syntax Error while loading YAML", pointing at a line and column. The play never runs because the document cannot be parsed.
ERROR! Syntax Error while loading YAML.
mapping values are not allowed in this context
The error appears to be in '/runner/_work/repo/site.yml': line 8, column 22
msg: Deploy complete: v1.2 <-- the unquoted colon breaks parsingCommon causes
Unquoted colon or special character
A value like "Deploy: v1" without quotes makes YAML read a mapping where a scalar was intended.
Indentation or a leading Jinja brace
Wrong indentation, or a value starting with {{ at the line start, must be quoted or YAML rejects it.
How to fix it
Quote ambiguous values and fix indentation
Wrap values with colons or leading braces in quotes, and keep consistent two-space indentation.
- name: Notify
debug:
msg: "Deploy complete: v1.2" # quotes protect the colon
- name: Templated
debug:
msg: "{{ release_version }}" # quote leading Jinja bracesHow to prevent it
- Quote values containing colons or starting with Jinja braces.
- Use consistent two-space indentation; avoid tabs.
- Run --syntax-check (and yamllint) in CI before the play.