1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
[![Build Status](https://travis-ci.org/voxpupuli/puppet-syntax.svg?branch=master)](https://travis-ci.org/voxpupuli/puppet-syntax)
[![Gem Version](https://img.shields.io/gem/v/puppet-syntax.svg)](https://rubygems.org/gems/puppet-syntax)
[![Gem Downloads](https://img.shields.io/gem/dt/puppet-syntax.svg)](https://rubygems.org/gems/puppet-syntax)
# Puppet::Syntax
Puppet::Syntax checks for correct syntax in Puppet manifests, templates, and
Hiera YAML.
## Version support
Puppet::Syntax is supported with:
- Puppet >= 5.0 that provides the `validate` face.
- Ruby >= 2.4
For the specific versions that we test against, see the [TravisCI config](.travis.yml).
## Installation
To install Puppet::Syntax, either add it to your module's Gemfile or install
the gem manually.
* To install with the Gemfile, add:
```ruby
gem 'puppet-syntax'
```
And then execute:
```sh
bundle install
```
* To install the gem yourself, run:
```sh
gem install puppet-syntax
```
## Configuration
To configure Puppet::Syntax, add any of the following settings to your `Rakefile`.
* To exclude certain paths from the syntax checks, set:
```ruby
PuppetSyntax.exclude_paths = ["vendor/**/*"]
```
* To configure specific paths for the Hiera syntax check, specify `hieradata_paths`. This is useful if you use Hiera data inside your module.
```ruby
PuppetSyntax.hieradata_paths = ["**/data/**/*.yaml", "hieradata/**/*.yaml", "hiera*.yaml"]
```
* To configure specific paths for the Puppet syntax checks or for the templates checks, specify `manifests_paths` or `templates_paths` respectively. This is useful if you want to check specific paths only.
```ruby
PuppetSyntax.manifests_paths = ["**/environments/future/*.pp"]
PuppetSyntax.templates_paths = ["**/modules/**/templates/*.erb"]
```
* To ignore deprecation warnings, disable `fail_on_deprecation_notices`. By default, `puppet-syntax` fails if it encounters Puppet deprecation notices. If you are working with a legacy code base and want to ignore such non-fatal warnings, you might want to override the default behavior.
```ruby
PuppetSyntax.fail_on_deprecation_notices = false
```
* To enable a syntax check on Hiera keys, set:
```ruby
PuppetSyntax.check_hiera_keys = true
```
This reports common mistakes in key names in Hiera files, such as:
* Leading `::` in keys, such as: `::notsotypical::warning2: true`.
* Single colon scope separators, such as: `:picky::warning5: true`.
* Invalid camel casing, such as: `noCamelCase::warning3: true`.
* Use of hyphens, such as: `no-hyphens::warning4: true`.
## Usage
* To enable Puppet::Syntax, include the following in your module's `Rakefile`:
```ruby
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`:
```ruby
task :test => [
:syntax,
:lint,
:spec,
]
```
* To test all manifests and templates, relative to the location of the `Rakefile`, run:
```
$ bundle exec rake syntax
---> syntax:manifests
---> syntax:templates
---> syntax:hiera:yaml
```
* To return a non-zero exit code and an error message on any failures, run:
```
$ 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:
* `**/data/**/*.yaml`
* `hieradata/**/*.yaml`
* `hiera*.yaml`
### 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.
|