Tim Sharpe

Home :: Projects :: About Me

Fix Simple Problems With puppet-lint

Since the first release of puppet-lint, one of the top two feature requests has been the ability to automatically fix trivial style issues (detecting problems is all well and good but no one wants to manually fix the eleventy thousand problems that have accumulated over the years).

To that end, I have just shipped a beta release of puppet-lint (0.4.0.pre1) which includes the experimental fixing support! I highly encourage everyone to give it a try and report any issues they find.

Currently, puppet-lint supports fixing a limited subset of detectable problems. There will probably be more added to this list over time however some problems will always require a human to decide how to proceed.

At this time, puppet-lint do the following for you:

  • Converting // comments into # comments.
  • Quoting unquoted resource titles.
  • Quoting unquoted file mode strings.
  • Converting 3 digit octal file modes into 4 digit modes.
  • Converting double quoted strings without variables into single quoted strings.
  • Converting double quoted strings that only contain a variable into an unquoted variable.
  • Enclosing variables in double quoted strings that haven't been enclosed in braces.
  • Unquoting quoted boolean values.
  • Converting hard tabs into 2 space soft tabs.
  • Removing trailing whitespace.
  • Fixing arrow (=>) alignment in resources and hashes.

Caveat Emptor

Running puppet-lint with fix mode enabled is a potentially destructive action.

I'm going to assume that your manifests are stored in some sort of version control and that you're comfortable discarding the changes puppet-lint makes if you don't like them.

Trying it out

First of all install the new version, either with RubyGems:

1 gem install --pre puppet-lint -v 0.4.0.pre1

or Bundler:

1 gem 'puppet-lint', '0.4.0.pre1'

Then just call puppet-lint with the -f or --fix option

1 $ puppet-lint -f test.pp
2 FIXED: double quoted string containing no variables on line 1
3 FIXED: string containing only a variable on line 3
4 FIXED: indentation of => is not properly aligned on line 5
5 FIXED: unquoted file mode on line 5
6 FIXED: mode should be represented as a 4 digit octal value or symbolic mode on line 5

And the diff of the changes to my test file is

 1 diff --git a/test.pp b/test.pp
 2 index 7cd1e93..4d455cf 100644
 3 --- a/test.pp
 4 +++ b/test.pp
 5 @@ -1,6 +1,6 @@
 6 -$foo = "/tmp/foo"
 7 +$foo = '/tmp/foo'
 8 
 9 -file { "$foo":
10 +file { $foo:
11    ensure => present,
12 -  mode => 444,
13 +  mode   => '0444',
14  }

So, please try it out and create an issue on the repository if you run into any problems!