4

I recently ran puppet module generate, and ended up with a whole lot of crap that looked unnecessary for a simple module. I mean, a lot of minimal modules amount to templating a configuration file or two and letting an open source Puppet module do the heavy lifting.

Puppet's documentation explained most of puppet module generate here:

https://docs.puppet.com/puppet/4.9/modules_fundamentals.html

However, I didn't see anything in there about the Gemfile.

Of what use is the Gemfile generated by puppet module generate?

$ puppet module generate nathan-myapp_consul
$ cd myapp_consul/
$ ls
Gemfile     README.md   Rakefile    examples    manifests   metadata.json   spec

Here are the contents of this file:

source ENV['GEM_SOURCE'] || 'https://rubygems.org'

puppetversion = ENV.key?('PUPPET_VERSION') ? ENV['PUPPET_VERSION'] : ['>= 3.3']
gem 'metadata-json-lint'
gem 'puppet', puppetversion
gem 'puppetlabs_spec_helper', '>= 1.0.0'
gem 'puppet-lint', '>= 1.0.0'
gem 'facter', '>= 1.7.0'
gem 'rspec-puppet'

# rspec must be v2 for ruby 1.8.7
if RUBY_VERSION >= '1.8.7' && RUBY_VERSION < '1.9'
  gem 'rspec', '~> 2.0'
  gem 'rake', '~> 10.0'
else
  # rubocop requires ruby >= 1.9
  gem 'rubocop'
end

Gemfile produced by puppet module generate, what is the point of you?

1

A Gemfile is used by Ruby's Bundler app to install RubyGems (Ruby libraries) used by the project - in this case, gems that can be used to develop the module. It's not used when installing or using the module within Puppet.

If you have Ruby installed, you can install these gems by running:

gem install bundler
bundle install  # or add `--path vendor` to install within the directory

A quick run-down of the purpose of these gems, and why you might find them useful:

  • metadata-json-lint verifies the metadata.json file is correct, otherwise Puppet may not load the module and you couldn't upload it to the Forge
  • puppetlabs_spec_helper is a helper for running tests etc.
  • puppet-lint validates your Puppet manifests against the Puppet style guide (more info)
  • rspec-puppet, rspec let you write tests for Puppet classes, defined types etc to check that they compile without errors and create the right resources with the correct parameters (more info)
  • rake is used to run preconfigured tasks from Rakefile, i.e. rake test will run all of the above and also validates manifests, ERB files etc.
  • rubocop validates your Ruby code against a Ruby style guide, the equivalent to puppet-lint

As you suggest, these aren't necessary for a minimal module, but they are useful. You don't need to write tests or even lint your code, but using the tools may help you create a more reliable module and help you make changes without the risk of it not working within Puppet.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.