Puppet Module Basics 2

Adding continuous integration


4 minute read


This is part 2 of a series in the (advanced?) basics of Puppet modules. We are going to be covering the use of Travis CI to perform some automated testing using puppet-lint and rspec-puppet. This is a learning experience for me as much as you since it’s my first time using Travis CI (although not my first time using CI tooling).


If you haven’t checked out Part 1 of this series you should really have a read before proceeding.

At the end of the first installment we had created our Vagrant environment and the pmb class was being applied to all nodes. The module doesn’t really do anything other than output the operatingsystem fact, but that’s fine for now. We’ll be working on the module in this installment, but we won’t be adding any functionality just yet. Adding some scaffold testing and getting it automated is the goal.


I’ve basically followed this guide from Puppet for setting up our initial tests. Conveniently this commit shows what files we have added into the pmb module. I won’t bother stepping through what it all does because there are plenty of resources out there that do a better job, including two I have already linked. The testing provided in the commit doesn’t really do anything other than test the class exists if the class is declared, but remember our module doesn’t actually do anything yet so it’s no surprise the testing doesn’t do anything either. It does however provide a starting point for further testing as we develop our module.

In a separate commit I’ve created a Rakefile and defined the default task to run puppet-lint and rspec-puppet tests. At this point we could jump straight to Travis CI configuration, however there’s something else worth touching on first.


Strictly speaking you don’t need to do this as our goal is to offload testing to Travis CI.

There are still reasons to test locally though:

  • You can write/test your code offline
  • You aren’t wasting resources by repeatedly re-running tests remotely
  • People don’t see all your mistakes! (sometimes there are lots)

In order to perform local testing we need a few gems installed:

gem install puppet -v 3.8.7
gem install puppet-lint
gem install puppetlabs_spec_helper
gem install rspec-puppet

NOTE: I’ve picked Puppet 3.8.7 because it works with the OS version of Ruby on El Capitan (OS X) and I don’t want explain RVM in this installment. Our automated testing will cover newer versions of Puppet anyway, so anything here is better than nothing.

Once the gems are installed we can take a look at the output of rake lint and rake spec:

MBP13:puppet-pmb pckls$ rake lint
MBP13:puppet-pmb pckls$ rake spec
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -I/Library/Ruby/Gems/2.0.0/gems/rspec-support-3.4.1/lib:/Library/Ruby/Gems/2.0.0/gems/rspec-core-3.4.4/lib /Library/Ruby/Gems/2.0.0/gems/rspec-core-3.4.4/exe/rspec --pattern spec/\{classes,defines,unit,functions,hosts,integration,types\}/\*\*/\*_spec.rb --color

Finished in 0.10241 seconds (files took 1.13 seconds to load)
1 example, 0 failures

MBP13:puppet-pmb pckls$

We don’t see any errors, so it’s onwards to configure the CI steps!


Getting Travis CI watching your GitHub repos is so simple I’m not even going to explain it.

I did some googling for guides on setting up Puppet modules with Travis CI and found some good blog posts:

Unfortunately neither of these were exactly what I was after and I kind of combined certain aspects of both. Additionaly I used the Travis CI getting started guide as well the customising the build guide to author my initial CI configuration.

I’ve picked Ruby/Puppet versions that follow the Puppet Enterprise component version table because I consider these to be supported combinations. It doesn’t mean you have to use Puppet Enterprise, but if those are the combinations that Puppet support, it makes sense for us to consider matching this even if going down the open source route (at least in my opinion).

This is where things didn’t go quite as smoothly as I hoped, but that’s ok! As I previously mentioned this was going to be a learning experience for me as well. Instead of triggering the combinations I was after I ended up triggering every possible combination, which resulted in many failures!

Eventually I ended up with a working configuration, everything was green and I was happy!


I think this was quite easy to get working. I have had some experience with rspec-puppet before and that may have helped. Some of the frustrations I encountered when first setting it up were around missing gems in my local environment. With the addition of Travis CI most of the frustration was around getting my build matrix correct. Now that all of this is complete I think we have a solid module scaffold that we can begin to add more functionality to.

comments powered by Disqus