Syntax checks for Puppet manifests, templates, and Hiera YAML.
This should work on any version of:
- Puppet >= 2.7 that provides the
- Ruby >= 1.8 with
You can see the matrix of specific versions that we currently test against in the TravisCI config.
If you're using
puppetlabs_spec_helper/rake_tasks and getting unexpected
non-zero exit codes then you should upgrade to puppetlabs_spec_helper
>= 0.8.0 which no longer has a conflicting rake task and now depends on
Include the following in your
Test all manifests and templates relative to your
➜ puppet git:(master) bundle exec rake syntax ---> syntax:manifests ---> syntax:templates ---> syntax:hiera:yaml
A non-zero exit code and error message will be returned for any failures:
➜ puppet git:(master) 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)
Use in conjunction with lint and spec tests for Continuous Integration:
task :test => [ :syntax, :lint, :spec, ]
.yaml files for syntax errors.
By default, the rake task will look for all
.yaml files under:
.pp files for syntax errors
.erb files for syntax errors
.epp files for syntax errors.
Note: This will only occur when Puppet version specified is Puppet 4+ or Puppet 3 with the future parser enabled
Paths can be excluded with:
PuppetSyntax.exclude_paths = ["vendor/**/*"]
When you are using a Puppet version greater then 3.2, you can select the future parse by specifying
PuppetSyntax.future_parser = true
If you are using some form of hiera data inside your module, you can configure where the
syntax:hiera:yaml task looks for data with:
PuppetSyntax.hieradata_paths = ["**/data/**/*.yaml", "hieradata/**/*.yaml", "hiera*.yaml"]
If you are trying to validate the syntax of code written for application orchestration, you can enable the
PuppetSyntax.app_management = true
app_management is supported on Puppet 4.3 or higher, defaulting to off. On Puppet 5, it is always enabled.
Deprecation notices will cause a failure by default, you can override this functionality by setting:
PuppetSyntax.fail_on_deprecation_notices = false
Common mistakes in key names in Hiera files will be reported:
- Leading :: in keys eg.
- Single colon scope seperators eg.
- Invalid camel casing eg.
- Use of hyphens eg.
This can be enabled by setting
PuppetSyntax.check_hiera_keys = true
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install puppet-syntax
- Fork it
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Add some feature')
- Push to the branch (
git push origin my-new-feature)
- Create new Pull Request