Skip to content
Latchkey

ansible-lint "yaml[line-length]" violation in CI

ansible-lint embeds yamllint. The yaml[line-length] rule fires when a line is longer than the configured limit (default 160). It is a formatting violation that fails the lint step under strict profiles.

What this error means

ansible-lint reports "yaml[line-length]: Line too long (NNN > 160 characters)" pointing at a specific file and line.

ansible-lint
yaml[line-length]: Line too long (182 > 160 characters)
roles/webserver/tasks/main.yml:24

Common causes

A line exceeds the yamllint limit

A long command, a big inline dict, or a long templated string pushes the line past the configured maximum.

The default limit is stricter than intended

The project has no yamllint config, so the default line-length applies more strictly than the team wants.

How to fix it

Wrap the long line

Use YAML folding or block scalars, or split a long dict across lines.

tasks/main.yml
- name: Run a long command
  ansible.builtin.command: >
    /usr/bin/tool --flag-one value-one
    --flag-two value-two --flag-three value-three

Adjust the line-length rule

Set a project line-length in yamllint config if the default is too strict, rather than disabling the rule everywhere.

.yamllint
# .yamllint
rules:
  line-length:
    max: 200
    level: warning

How to prevent it

  • Wrap long commands with folded scalars.
  • Set a project yamllint config with an agreed line length.
  • Run ansible-lint locally so formatting fixes land before CI.

Frequently asked questions

What causes ""yaml[line-length]""?
A long command, a big inline dict, or a long templated string pushes the line past the configured maximum.
How do I fix "yaml[line-length]"?
Use YAML folding or block scalars, or split a long dict across lines.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card