Ansible "Syntax Error while loading YAML ... mapping values not allowed" in CI
The YAML parser hit invalid structure, commonly an unquoted colon or a tab, and could not build the document. Ansible reports "Syntax Error while loading YAML" with the line where parsing broke.
What this error means
The run fails before any task with "ERROR! Syntax Error while loading YAML" and a hint such as "mapping values are not allowed in this context", pointing at a line and column.
ERROR! Syntax Error while loading YAML.
mapping values are not allowed in this context
The error appears to be in '/runner/site.yml': line 6, column 14Common causes
An unquoted value containing a colon
A string like msg: Deploying: prod has a second colon the parser reads as a new mapping, so quoting is required.
Tabs or inconsistent indentation
YAML forbids tabs for indentation; a stray tab or misaligned block breaks the document structure.
How to fix it
Quote values with special characters
- Open the line and column the error names.
- Quote any value that contains a colon, brace, or leading special character.
- Replace tabs with spaces and align the block.
- name: Print message
ansible.builtin.debug:
msg: "Deploying: prod"Syntax-check in CI
Validate structure before running so malformed YAML fails fast.
ansible-playbook --syntax-check site.ymlHow to prevent it
- Quote strings containing colons or braces.
- Use spaces, never tabs, for YAML indentation.
- Run
--syntax-checkand yamllint before merge.