- Puppet 3 Cookbook
- John Arundel
- 493字
- 2021-04-09 23:52:27
Checking your manifests with puppet-lint
The Puppet Labs official style guide outlines a number of style conventions for Puppet code, some of which we've touched on in the preceding section. For example, according to the style guide, manifests:
- Must use two-space soft tabs
- Must not use literal tab characters
- Must not contain trailing white space
- Should not exceed an 80 character line width
- Should align parameter arrows (
=>
) within blocks
Following the style guide will make sure that your Puppet code is easy to read and maintain and, if you're planning to release your code to the public, style compliance is essential. The puppet-lint
tool will automatically check your code against the style guide. Here's how to use it:
Getting ready
Here's what you need to do to install puppet-lint
:
- Run the following command (we'll install
puppet-lint
as a gem, because that version is much more up-to-date than the APT package available in the Ubuntu Precise repo):ubuntu@cookbook:~/puppet$ sudo gem install puppet-lint --no-ri --no-rdoc Successfully installed puppet-lint-0.3.2 1 gem installed
How to do it...
Follow these steps to use puppet-lint
:
- Choose a Puppet manifest file that you want to check with
puppet-lint
, and run the following command:ubuntu@cookbook:~/puppet$ puppet-lint modules/admin/manifests/ntp.pp WARNING: indentation of => is not properly aligned on line 9 ERROR: trailing whitespace found on line 13 WARNING: double quoted string containing no variables on line 3
- As you can see,
puppet-lint
found a number of problems with the manifest. Correct them, save the file, and rerunpuppet-lint
to check that all is well. If so, you'll see no output:ubuntu@cookbook:~/puppet$ puppet-lint modules/admin/manifests/ntp.pp ubuntu@cookbook:~/puppet$
There's more...
You can find out more about puppet-lint
at the website
The website lists each of the style checks in detail, and explains what the error messages mean and what to do about them.
Should you follow the Puppet style guide and, by extension, keep your code lint-clean? It's up to you, but here are a couple of things to think about:
- It makes sense to use some style conventions, especially when you're working collaboratively on code. Unless you and your colleagues can agree on standards for whitespace, tabs, quoting, alignment, and so on, your code will be messy and difficult to read or maintain.
- If you're choosing a set of style conventions to follow, the logical choice would be that issued by Puppet Labs and adopted by the community for use in public modules.
Having said that, it's possible to tell puppet-lint
to ignore certain checks if you've chosen not to adopt them in your codebase. For example, if you don't want puppet-lint
to warn you about code lines exceeding 80 characters, you can run puppet-lint
with the following option:
puppet-lint --no-80chars-check
Run puppet-lint --help
to see the complete list of check configuration commands.
- iPad+Procreate數字插畫設計案例教程(全彩微課版)
- Visio圖形設計從新手到高手(兼容版·第2版)
- AutoCAD 2014中文版完全自學手冊
- 中文版Premiere Pro CC實用教程
- Unity Game Development Essentials
- Mastering phpMyAdmin 3.3.x for Effective MySQL Management
- 音樂日記:Logic Pro X場景x風格編曲實用教程
- Photoshop CS6實戰基礎培訓教程(全視頻微課版)
- SPSS統計分析
- 中文版Photoshop CS6應用技法教程
- 三維建模與3D打印從入門到精通
- Photoshop CC入門與提高
- 中文版Maya 2014基礎培訓教程
- PKPM 2010結構分析從入門到精通
- Configuring IPCop Firewalls: Closing Borders with Open Source