A list of puppet modules, tools, testing, and architecture that are good references for current Puppet best practices.
- Puppet Tea - Custom Defined Types that can be used to shorten the parameter list definitions and/or when complex types are used in multiple places.
-
Puppet Development Kit - All-in-one CLI for writing and testing puppet modules (docs, announcement, github); provides Gemfile, Rakefile, Travis CI, Rubocop, and other settings you should use.
-
Modulesync helps synchronize consistent settings across modules in a user or organization namespace.
- modulesync_config reference is an example of a starting configuration.
-
puppet-retrospec The only tool you need to generate puppet code, tests, modules, facts, types, providers, data and everything else..
-
puppet-ghostbuster is a dead code detector. Requires puppetdb 3+.
-
puppet-debugger A interactive live debugger and REPL for the puppet language
-
puppet-strings generates automatic documentation for properly configured modules. See the Puppet blog for details.
- Puppet's NTP module is a recommended reference module.
- VSCode Plugin: syntax highlighting, code snippets, linting, IntelliSense (using your deployed modules), validation, import from
puppet resource
, node graph view, PDK integration (blog, VSCode) - JetBrain's RubyMine: style guide, syntax and error highlighting, some refactoring support, code completion, structure view download
- vim-puppet: provides syntax highlighting and other plugins for editing puppet files.
- Atom: syntax highlighting, linting
-
Introduction to Testing Puppet Modules (slides and video) by David Schmitt
The modules below each highlight one or more aspects of rspec-puppet testing.
- Resource API
- Legacy examples:
- puppetlabs/java's java_version
- puppetinabox puppet_role fact and test - The puppet_role fact is calculated on another fact's value, hostname, which requires resetting BOTH custom facts for every test.
If you have a puppet 4 function that is called and you don't want it to execute and want to create a mock/fake to be used in the real one's place you can use the puppet-rpsec precondition. This function definition will override will be added to the loader and the original function will not be attempted to be loaded from disk since there already exists the function, your mock!
# Puppet code that calls puppet 4 function
class profile::sqlserver {
$iso_location = 'C:/SW_DVD9_SQL_Svr_Ent_Core_2012_English_MLF_X17-99682.IMG'
googlecloudstorage::gcpsignedfile { $iso_location:
ensure => 'present',
signed_url => googlecloudstorage::generate_signed_url('20m', '/etc/puppetlabs/puppetserver/ssh/Terraform-puppet-credentials.json', 'gs://puppet-provisioning-binaries/SQL Server 2012 - Enterprise Edition/SW_DVD9_SQL_Svr_Ent_Core_2012_English_MLF_X17-99682.IMG'),
# signed_url => 'https://asdasdasd.com/file.iso',
mounted => true,
}
}
# Puppet 4 function
# @param [String] duration
# Example use case
#
# with s = seconds, m = minutes, h = hours, d = days
require 'open3'
Puppet::Functions.create_function(:'googlecloudstorage::generate_signed_url') do
# Signatures
dispatch :generate_signed_url do
required_param 'Pattern[/(s)|(m)|(h)|(d)$/]', :duration
required_param 'String', :private_key_file
required_param 'String', :google_cloud_storage_url
return_type 'String'
end
# Implementations
def generate_signed_url(duration, private_key_file, google_cloud_storage_url)
Puppet.info("duration: #{duration}")
Puppet.info("private_key_file: #{private_key_file}")
Puppet.info("google_cloud_storage_url: #{google_cloud_storage_url}")
stdout, stderr, status = Open3.capture3("gsutil signurl -d #{duration} '#{private_key_file}' '#{google_cloud_storage_url}'")
if not status.success?
raise Puppet::ParseError, "gcloud failure: exitcode #{status.exitstatus} stdout #{stdout} stderr #{stderr}"
end
return stdout.split(' ')[-1]
end
end
# Test
require 'spec_helper'
describe 'profile::sqlserver' do
context 'with default values for all parameters' do
let(:pre_condition) {
'function googlecloudstorage::generate_signed_url($x, $y, $z) { return \'https://asdasdasd.com/file.iso\' }'
}
it { should contain_googlecloudstorage__gcpsignedfile('C:/SW_DVD9_SQL_Svr_Ent_Core_2012_English_MLF_X17-99682.IMG').with({
:ensure => 'present',
:signed_url => 'https://asdasdasd.com/file.iso',
}) }
end
end
- puppetlabs/apache's defined type apache::vhost requires the class
apache
to be included as well, vialet :pre_condition do .. end
Templates are often fed values by class parameters. Test for portions of the content based on the values you expect to find with various parameter settings, rather than testing the entire contents.
- puppetlabs/apache - httpd.conf.erb's DefaultType setting is tested here
A Control Repository is used to control the code deployed in Puppet environments. Puppet has two official reference repositories, and there are some public repositories that are a mix of reference architecture and practical usage.
- puppetlabs/control-repo - Official reference architecture from Puppet, based on Even Besterer Practices.
- puppetlabs-education/classroom-control-vf - A good reference implementation of the control repository, maintained by Puppet's Education group.
- example42/control-repo - Example 42's reference control repository.
- puppetinabox/controlrepo - Rob Nelson's control repository for his PuppetInABox project.
- Whirlwind Tour of Puppet 4 - Slides and video
- Puppet Cookbook, a collection of task oriented solutions in Puppet
- YAML for Puppet users? - A combination YAML primer and Guide to Puppet/YAML idiosyncracies.