Prior to Puppet 4, Puppet 3 had a preview of the Puppet 4 language named the future parser. The future parser feature allowed you to preview the language changes that would be coming to Puppet 4 before upgrading. Most of these features were related to iterating on objects and have been carried forward to Puppet 5. In this section, we will cover the major changes in Puppet 5. A good place to check for language changes are the release notes. While writing this book, I'm using Puppet 5.5.2, so I need to check the release notes for Puppet 5.5(https://puppet.com/docs/puppet/5.5/release_notes.html), 5.0 (https://puppet.com/docs/puppet/5.0/release_notes.html), 5.1 (https://puppet.com/docs/puppet/5.1/release_notes.html), 5.2 (https://puppet.com/docs/puppet/5.2/release_notes.html), and 5.3 (https://puppet.com/docs/puppet/5.3/release_notes.html).
Puppet 5 changes
Using the call function
Puppet 5 adds a new function, call. This function is useful for calling a function by name using a variable. In the following example, we change the function we use depending on a variable:
if versioncmp($::puppetversion,'4.0') {
$func = 'lookup'
} else {
$func = 'hiera'
}
$val = call($func,'important_setting')
notify {"\$val = $val, \$func = $func": }
If the version of Puppet is lower than 4.0, the hiera function will be called; if not, lookup will be used.