Manage Puppet Modules using librarian-puppet

Manage Puppet Modules using librarian-puppet

When you have setup a Puppet based infrastructure which involves several modules which are spread over different places. Meaning different modules has different source and each or some of those modules have it’s own set of dependencies. The source of the modules can be Puppet Forge or some GIT Repositories or tar files available over the web or some local module.

It becomes very difficult to keep a track of such dependencies and their source. So what do we do in such case?

There are several options available which can be used in such situation.

  • Git submodules – This basically is a very basic available tool to handle multiple Puppet modules. So in this method you add GIT repositories of other modules as git submodule. Now all you need to do is git submodule init to initialize local configuration file and git submodule update to fetch the data from the remote project.
  • Puppet module tool (PMT) – PMT will basically install modules from Puppet Forge. It can basically search for modules using the module name and/or provider and install them.
  • Librarian-puppet – This basically is an extension of Ruby‘s bundler model to install gems. In case of Ruby bundler we use Gemfile to list and define your dependencies. In case of librarian-puppet, we use Puppetfile. Once the dependencies are in librarian-puppet a .lock file will appear with resolved dependencies.
  • So librarian-puppet is used to manage your Puppet Infrastructure. It is used to manage the Puppet modules your infrastructure depends on. The source of these modules can be either Puppet Forge, GIT repositories or a local path.

    Librarian-puppet manages your modules/ directory based on your Puppetfile. The Puppetfile becomes the authoritative source to define what modules are required along with the version or tag or branch to use.

    If using librarian-puppet you should not modify the contents for modules/ directory. Any changes to the module version or repository path or branch are to be made in Puppetfile.


    Any puppet repository which uses librarian-puppet can have a file named Puppetfile, metadata.json or Modulefile in the root of the repository. All the module dependencies for your puppet infrastructure repository is defined in it.

    We will go through some modules declaration from different sources here.

    Puppet Forge

    If you have a module to be installed from Puppet Forge you have to first define the default source. So if we want to use official Puppet Labs Forge to get the modules from we have to mention the forge in Puppetfile

    forge ""

    With the source defined you can now start defining the modules you want it to install. The format is forge provider and the module name.

    mod 'puppetlabs/ntp'

    This will install the latest version for NTP Puppet module provided by Puppet Labs.

    Optionally you can specify the version you want. So in the above case we can also specify to get version 3.0.1 for Puppet Labs NTP module.

    mod 'puppetlabs/ntp', '3.0.1'


    Modules can be cloned from some GIT repository as well.

    mod 'puppetlabs-apt',
       :git => "git://"

    The above will checkout from the master branch for apt module from Puppet Labs GitHub repository.

    We can also define some other branch or some tag from a GIT repo.

    Continuing the above example, we will use tag beta for apt module from Puppet Labs GitHub repo.

    mod 'puppetlabs-apt',
       :git => "git://",
       :ref => 'beta'

    Or we will use the branch release_candidate

    mod 'puppetlabs-apt',
       :git => "git://",
       :ref => 'release_candidate'

    So if no :ref => is mentioned librarian-puppet will checkout the master branch. You can also mention SHA (the GIT commit number) as :ref =>.

    Lastly, in GIT method you can provide the path to some folder inside a repository. Librarian-puppet will navigate inside the GIT repository to get the contents.

    mod 'puppetlabs-apt',
       :git => "git://",
       :path => 'new_releases/rc2'

    Local Path

    Similar to the :path => option provided above in GIT, we can do the same for locally available modules.

    mod 'my_local_module',
       :path => '/usr/puppet/base/module/my_local_module'

    Manage Puppet Modules using librarian-puppet – How to use


    Librarian-puppet is a Ruby gem which you need to install using gem

    $ gem install librarian-puppet

    In case you do not have Ruby and intend to install it, I highly recommend doing so using Ruby Version Manager (RVM).


    Prepare Puppet Infrastructure repository for librarian-puppet.

    Go to the Puppet Infrastructure repository to be managed and remove the modules/ directory.

    $ cd /path/to/puppet-infra-repos
    $ rm -rf modules/

    Now initialize librarian-puppet using the following command:

    $ librarian-puppet init

    It will now take over the modules/ directory for the puppet repository. Since the modules/ directory is managed by librarian-puppet you don’t need to track it in GIT. Librarian-puppet uses .tmp/ directory for cache and temporary files. This directory isn’t required to be tracked in GIT as well.

    Running the above command will create a skeleton Puppetfile and add modules/ and .tmp/ in .gitignore file.

    Run Librarian-puppet

    After ensuring you have all the dependencies defined in Puppetfile you can now run Librarian-puppet to get the required modules.

    Run the following.

    $ librarian-puppet install

    This command looks at each mod declaration and fetches the module from the source specified. This command writes the complete resolution into Puppetfile.lock and then copies all of the fetched modules into your modules/ directory, overwriting whatever was there before.

    Manage Puppet Modules using librarian-puppet

    No Comments

    Post a Comment

    Time limit is exhausted. Please reload CAPTCHA.