yamllint "wrong indentation" error in CI
yamllint's indentation rule enforces a fixed step (2 spaces by default). A line indented by a different amount, or a tab, triggers "wrong indentation: expected N but found M".
What this error means
yamllint reports "wrong indentation: expected N but found M (indentation)" on a nested key or list item. The file may still parse, but the style rule fails the job.
deploy.yml
5:5 error wrong indentation: expected 4 but found 5 (indentation)Common causes
Inconsistent space counts between nested levels
One block uses 2 spaces and another uses 3 or 5, so a child sits at an offset the indentation rule does not allow.
A tab character standing in for spaces
An editor inserted a tab; YAML forbids tabs for indentation and yamllint flags the resulting width as wrong.
How to fix it
Normalize to the configured step
- Set your editor to insert 2 spaces per indent and never tabs.
- Re-indent the flagged block to a multiple of the step.
- Re-run
yamllintto confirm the rule passes.
# yamllint config: allow a consistent 2-space step
rules:
indentation:
spaces: 2
indent-sequences: trueConvert tabs to spaces
Expand any leading tabs to spaces so widths are computed consistently.
sed -i 's/\t/ /g' deploy.ymlHow to prevent it
- Add an
.editorconfigenforcing 2-space indent for*.yml. - Run yamllint in a pre-commit hook to catch drift before CI.
- Never mix tabs and spaces in YAML files.