Search code examples
puppet

Puppet module use


Right, I've been using Puppet for approx. 4 hours so have a total n000b question. I've downloaded and installed a puppet module using:

puppet module install resolv_conf

All well and good. It has installed the module into:

/home/user/.puppet/modules/, again all well and good.

The module shows up when I run puppet module list, which I'm guessing it's supposed to.

So my question is how do I use the module?

I get that somewhere I need to add to a manifest,

class { 'resolv_conf': nameservers => ['192.168.0.254', '8.8.8.8'], }

but I'm assuming that I don't add that in the

/home/user/.puppet/modules/resolv_conf/manifests/init.pp file.

I tried creating a folder and init.pp file here

/etc/puppet/modules/resolv_conf/manifests

and added the class to it, but I get

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Puppet::Parser::AST::Resource failed with error ArgumentError: Could not find declared class resolv_conf at /etc/puppet/modules/resolv_conf/manifests/init.pp:4 on node rarity.home

So I'm a bit stumped. Can some kind soul point me in the right direction?

Fanks :)


Solution

  • So by default, the puppet module command will download modules into a local directory.

    Assuming your master is running correctly, you need to install the module into your $modulepath, you can find your $modulepath on the master by doing:

    puppet config print modulepath
    

    Which depending on your version of Puppet (I'm running v4, so if you're on v3 it may be slightly different), will return something like this:

    /etc/puppetlabs/code/environments/production/vendor:/etc/puppetlabs/code/environments/production/modules:/etc/puppetlabs/code/modules:/opt/puppetlabs/puppet/modules
    

    Install your module into one of those directories using the Puppet Module command like so:

    puppet module install -i /etc/puppetlabs/code/modules
    

    Now, your master will understand and be able to read to resolv_conf module, but you need to apply it to your nodes. In order to do that you need to set up node definitions

    So within one of your $modulepaths you'll need to have a directory manifests containing a single manifest, site.pp which is called the "main manifest"

    Inside there, create a node definition for your agent similar to the one in the example:

    node 'www1.example.com' {
      include resolv_conf
    }
    

    This is the simplest set up you can have. Some further reading:

    • r10k can automate the downloading of modules for you
    • a control repo is a suggested way of laying out your puppet repo
    • an ENC is a better way of classifying your nodes than using the site.pp

    Good luck!