Infrastruktur – News

Getting your code ready for Puppet 4

6 Februar 2015

Puppet 4 is just around the corner and it will bring a good deal of changes. Some of them will require to adapt or fix your code, as outlined at Puppetcamp Amsterdam last week by Martin Alfke:

Power of Puppet 4 from Martin Alfke

Now the problem is, “How do you find the code that needs fixing, and how do you fix it easily?”

This is where puppet-lint chimes in!

At Camptocamp, we have written a series of puppet-lint plugins to ease the transition to the future parser – and eventually, Puppet 4.

Future parser plugins

Find out potential problems in your code when migrating to Puppet 4.

  • puppet-lint-unquoted_string-check: This plugin checks that selectors and case statements are properly quoted. Unquoted statements will fail to be evaluated properly with the future parser.
  • puppet-lint-empty_string-check: In the future parser, the empty string is true (just like in Ruby), which has never been the case in Puppet before. This is problematic if you use the empty string as the default value for a variable, and expect to check that the variable was changed with a simple if $varname.
  • puppet-lint-leading_zero-check: In Puppet 4, unquoted numbers will be automatically casted. This means that any number with a leading zero that is not quoted will lose that leading zero. This can be problematic in file modes (puppet-lint already checks this for file resources, but it might happen in wrapping definitions or classes) or order parameters (concat fragments, for example).
  • puppet-lint-variable_contains_upcase: Our team at Camptocamp didn’t write this plugin, Chris Spence did. It has however been a useful addition to help migrating to the future parser. This plugin checks for variables whose name contains an uppercase character, which will fail with the future parser.

Other plugins

The previous plugins were specifically written to ease the transition to the future parser. But before you prepare for Puppet 4, there are already errors you can avoid in Puppet 3 with additional puppet-lint plugins.

  • puppet-lint-spaceship_operator_without_tag-check: The spaceship operator can help manageing complex dependencies in Puppet code. However, it has the side effect of realizing all virtual resources that match the collector expression. This plugin checks for spaceship operators used without a tag condition.
  • puppet-lint-absolute_classname-check: When including a class (using either functions such as ‘include’, ‘require’, or ‘contain’, or the ‘class { }’ syntax), Puppet uses a relative name resolution. This can sometimes lead to unexpected results, the worst being a class including itself silently (which happens if you include the ‘apache’ class from within a class named ‘profile::apache’, for example). This behavior is fixed in the future parser, but it can be avoided in Puppet 2 and 3 by adding ‘::’ in front of the class name. This is what this plugin does.
  • puppet-lint-undef_in_function-check: When passing the ‘undef’ value to a Puppet function, Puppet munges it into an empty string. This plugin checks for ‘undef’ as a function parameter.
  • puppet-lint-roles_and_profiles-check: This plugin helps enforce the good practices of roles and profiles.