Skip to content

Instantly share code, notes, and snippets.

@brasey
Created November 18, 2014 20:58
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save brasey/030b318a37b07acd21af to your computer and use it in GitHub Desktop.
Save brasey/030b318a37b07acd21af to your computer and use it in GitHub Desktop.
Masterless Puppet using a Puppetfile

Masterless Puppet using a Puppetfile

The problem

When running Puppet in masterless mode, meaning there is no Puppet Master for the node to connect to, one of the problems you have to solve is how to get all your Puppet modules onto the node. Without going into all the possible ways of doing this, one nice and clean way to solve the problem is to use a Puppetfile.

If you know what a Ruby gemfile is, you can guess what a Puppetfile is. If you don't, think of a very simple list declaring the modules that a node should get, including ways to get those modules. Like this:

forge 'forge.puppetlabs.com'

mod 'maestrodev/wget'

mod 'painkeep',
  :git => 'https://github.com/brasey/painkeep'

Here's an example showing off several ways to declare a module:

# Install puppetlabs/apache and keep it up to date with 'master'
mod 'apache',
  :git => 'https://github.com/puppetlabs/puppetlabs-apache'

# Install puppetlabs/apache and track the 'docs_experiment' branch
mod 'apache',
  :git => 'https://github.com/puppetlabs/puppetlabs-apache',
    :ref => 'docs_experiment'

# Install puppetlabs/apache and pin to the '0.9.0' tag
mod 'apache',
  :git => 'https://github.com/puppetlabs/puppetlabs-apache',
    :tag => '0.9.0'

# Install puppetlabs/apache and pin to the '83401079' commit
mod 'apache',
  :git    => 'https://github.com/puppetlabs/puppetlabs-apache',
    :commit => '83401079053dca11d61945bd9beef9ecf7576cbf'

# Install puppetlabs/apache and track the 'docs_experiment' branch
mod 'apache',
  :git    => 'https://github.com/puppetlabs/puppetlabs-apache',
    :branch => 'docs_experiment'

Taken from here.

How to do it

r10k

I don't know how anyone does anything with Puppet without using r10k. If your Puppet modules are in version control (looking at you) and you use modules from the Puppet Forge, or any other place, r10k is the magic that ties it all together. It even makes your git branches magically turn into environments on a Puppet master, but that's a story for another day.

It lives here.

Puppetfile location

The Puppetfile should be in the same directory where your 'modules' directory lives. If for you that is /etc/puppet/modules, then your Puppetfile should be at /etc/puppet/Puppetfile.

Invocation

cd /etc/puppet
sudo r10k puppetfile install

That will pull down whatever you have defined in your Puppetfile into /etc/puppet/modules. Now you just have to run Puppet:

sudo puppet apply --modulepath=/etc/puppet/modules /etc/puppet/manifests/site.pp

assuming you've defined your entrypoint at that site.pp location. You could point somewhere else if you need to.

@lmayorga1980
Copy link

I always like the idea of using Puppet Masterless in a more distributed mode. I believe we can also mix hiera into the picture for the puppet apply too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment