Puppet Code Quality: puppet-lint, Syntax Validation and Style Guide

Puppet Training Course 18 min min read Updated: Nov 17, 2026 Beginner
Puppet Code Quality: puppet-lint, Syntax Validation and Style Guide
Beginner Topic 1 of 3

Why Check Code Automatically?

A typo in a manifest may only show up when an agent runs on production. Automatic checks find syntax errors, style problems and risky patterns in seconds, on your laptop and in CI, before anything is deployed.

Syntax Validation

bash puppet parser validate manifests/site.pp puppet parser validate $(find . -name '*.pp' -not -path './modules/*') puppet epp validate templates/*.epp erb -P -x -T '-' templates/app.conf.erb | ruby -c # ERB templates ruby -c lib/facter/my_fact.rb yamllint data/ hiera.yaml # install: pip install yamllint python3 -c "import json,sys; json.load(open('metadata.json'))"

puppet parser validate checks only syntax. It does not know whether a class exists or whether your variables are valid. Unit tests catch those problems (next lessons).

puppet-lint

bash gem install puppet-lint # or use: pdk validate puppet-lint manifests/ puppet-lint --fix manifests/ # fix simple problems automatically puppet-lint --no-140chars-check manifests/init.pp puppet-lint --fail-on-warnings manifests/ # non-zero exit when warnings exist (good for CI)
text manifests/init.pp - WARNING: double quoted string containing no variables on line 7 manifests/init.pp - WARNING: unquoted file mode on line 12 manifests/init.pp - WARNING: arrow should be on the right operand's line on line 15 manifests/init.pp - ERROR: tab character found on line 22 manifests/init.pp - WARNING: top-scope variable being used without an explicit namespace on line 30
Common warningFix
double quoted string containing no variablesUse single quotes: 'text'
unquoted file modeWrite mode => '0644'
arrow alignmentAlign => arrows in each resource block
variable not enclosed in {}In strings use "${name}"
class not documentedAdd @summary and @param comments
ensure should be the first attributePut ensure first in a resource
top-scope variableUse $facts['x'] or $::x carefully; prefer $facts
legacy factsUse $facts['os']['family'] instead of $osfamily
trailing whitespace, tab characterClean spaces and use 2-space indentation
140charsBreak long lines

Configuration File

text # ~/.puppet-lint.rc or .puppet-lint.rc in the project --fail-on-warnings --no-140chars-check --no-documentation-check --relative --ignore-paths=modules/*,vendor/**/*.pp,spec/fixtures/**/*.pp
puppet # Disable a check for one line, with a reason $x = "$a" # lint:ignore:only_variable_string (legacy reasons) # lint:ignore:80chars $long_line = 'a very long string ... ' # lint:endignore

Style Guide Summary

TopicRule
Indentation2 spaces, never tabs
StringsSingle quotes unless interpolating
Resource titlesAlways quote them
Attribute arrowsAlign => within a resource
ensureFirst attribute
ModesQuoted four-digit strings: '0644'
Class namesLowercase, :: separated, matching the file path
VariablesLowercase snake_case, with $facts[...] instead of top-scope
ParametersTyped, with defaults where possible, documented
ConditionalsAlways include a default or else branch
CommentsExplain why, not what
Line lengthPrefer 140 characters or fewer
puppet # Before class ntp($servers=["a","b"]){ package{"chrony": ensure=>installed, } file { "/etc/chrony.conf": mode=>644, content=>template("ntp/chrony.erb") } } # After # @summary Manage time synchronization # @param servers List of time servers class ntp ( Array[String] $servers = ['a', 'b'], ) { package { 'chrony': ensure => installed, } file { '/etc/chrony.conf': ensure => file, mode => '0644', content => epp('ntp/chrony.conf.epp', { 'servers' => $servers }), } }

Editor Integration

  • VS Code: the Puppet extension runs lint on save and shows problems inline
  • Vim: syntastic or ALE with puppet-lint and puppet parser validate
  • IntelliJ: Puppet plugin
  • Make 'format on save' and 'trim whitespace' part of the shared editor configuration (.editorconfig)
ini # .editorconfig root = true [*] indent_style = space indent_size = 2 trim_trailing_whitespace = true insert_final_newline = true charset = utf-8

Pre-commit Hook

yaml # .pre-commit-config.yaml (pip install pre-commit; pre-commit install) repos: - repo: local hooks: - id: puppet-parser-validate name: puppet parser validate entry: puppet parser validate language: system files: \.pp$ - id: puppet-lint name: puppet-lint entry: puppet-lint --fail-on-warnings language: system files: \.pp$ - id: yamllint name: yamllint entry: yamllint language: system files: \.ya?ml$

CI Job

yaml # GitHub Actions name: lint on: [pull_request] jobs: lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: { ruby-version: '3.2', bundler-cache: true } - run: gem install puppet-lint - run: puppet-lint --fail-on-warnings site-modules manifests - run: pip install yamllint && yamllint data hiera.yaml

Practice Tasks

  1. Run puppet parser validate and puppet-lint on one of your earlier manifests and fix every warning
  2. Run puppet-lint --fix and review the diff before committing
  3. Create a .puppet-lint.rc that fits your team
  4. Set up a pre-commit hook and try to commit a file with a syntax error
  5. Add a lint job to your CI pipeline

Conclusion

Run puppet parser validate, puppet epp validate, puppet-lint and yamllint on every change, first in your editor, then in a pre-commit hook, then in CI. Follow the style guide so code stays easy to read.

Quick Summary: parser validate = syntax only; puppet-lint style; --fix; pre-commit; CI; typed documented parameters.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators