voxpupuli / puppet-syntax

Syntax checks for Puppet manifests and templates
MIT License
68 stars 51 forks source link
hacktoberfest

puppet-syntax

License Release Test RubyGem Version RubyGem Downloads

Puppet::Syntax

Puppet::Syntax checks for correct syntax in Puppet manifests, templates, and Hiera YAML.

Version support

Puppet::Syntax is supported with:

For the specific versions that we test against, see the GitHub Actions workflow.

Installation

To install Puppet::Syntax, either add it to your module's Gemfile or install the gem manually.

gem 'puppet-syntax'

And then execute:

bundle install
gem install puppet-syntax

Configuration

To configure Puppet::Syntax, add any of the following settings to your Rakefile.

PuppetSyntax.exclude_paths = ["vendor/**/*"]
PuppetSyntax.hieradata_paths = ["**/data/**/*.yaml", "hieradata/**/*.yaml", "hiera*.yaml"]
PuppetSyntax.manifests_paths = ["**/environments/future/*.pp"]
PuppetSyntax.templates_paths = ["**/modules/**/templates/*.erb"]
PuppetSyntax.fail_on_deprecation_notices = false
PuppetSyntax.check_hiera_keys = true

This reports common mistakes in key names in Hiera files, such as:

PuppetSyntax.check_hiera_data = true

Usage

require 'puppet-syntax/tasks/puppet-syntax'

For Continuous Integration, use Puppet::Syntax in conjunction with puppet-lint and spec tests. Add the following to your module's Rakefile:

task :test => [
  :syntax,
  :lint,
  :spec,
]
$ bundle exec rake syntax
---> syntax:manifests
---> syntax:templates
---> syntax:hiera:yaml
$ bundle exec rake syntax
---> syntax:manifests
rake aborted!
Could not parse for environment production: Syntax error at end of file at demo.pp:2
Tasks: TOP => syntax => syntax:manifests
(See full trace by running task with --trace)

Checks

Puppet::Syntax makes the following checks in the directories and subdirectories of the module, relative to the location of the Rakefile.

Hiera

Checks .yaml files for syntax errors.

By default, this rake task looks for all .yaml files in a single module under:

It will validate the syntax of each Hiera key. for values, it will check if the interpolation function syntax is correct. Wrong:

foo:
  "%{lookup('baz'):3306}": []

correct would be:

foo:
  "%{lookup('baz')}:3306": []

manifests

Checks all .pp files in the module for syntax errors.

templates

erb

Checks .erb files in the module for syntax errors.

epp

Checks .epp files in the module for syntax errors.

EPP checks are supported in Puppet 4 or greater, or in Puppet 3 with the future parser enabled.

Contributing

  1. Fork the repo.
  2. Create your feature branch (git checkout -b my-new-feature).
  3. Commit your changes (git commit -am 'Add some feature').
  4. Push to the branch (git push origin my-new-feature).
  5. Create new Pull Request.

Making a new Release