Ask Your Question
1

Is it possible possible to use autoloading and site.pp?

asked 2013-06-07 14:43:48 -0500

updated 2013-06-07 14:44:47 -0500

My puppet configuration looks like this:

manifests
  site.pp
  admin
    env.pp
    tools.pp
    jobs.pp    
modules
  ... a bunch of 3rd party modules ...

env.pp contains class admin::env, tools.pp contains class admin::tools etc.

If my site.pp looks like this:

node default {

  include admin::env
  include admin::tools
  include admin::jobs

}

Then I get an error: Error 400 on SERVER: Could not find class admin::env

But if I add import statements that import all *.pp files, then it works.

This looks a bit redunant that I need to define a class in separate file (according to ... (more)

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
2

answered 2013-06-09 11:54:10 -0500

supercow gravatar image

I strongly recommend (echoing ramindk's answer) that you change your layout to match something like this:

manifests
  site.pp
internal_modules
  admin
    manifests
      env.pp
      tools.pp
      jobs.pp    
modules
  ... a bunch of 3rd party modules ...

Then, in /etc/puppet/puppet.conf:

modulepath = /etc/puppet/modules:/etc/puppet/internal_modules

Your env.pp, tools.pp, and jobs.pp files would then look like this:

#in env.pp
class admin::env {
  # puppet code goes here
}

This is the way autoloading was designed to work, and adding a separate module path will solve your problem of intermixing with 3rd party modules.

edit flag offensive delete link more

Comments

1

This is very nitpicky, but I'd put the internal_modules path first so that internal modules will override 3rd party modules.

Ancillas gravatar imageAncillas ( 2013-06-10 01:11:33 -0500 )edit
2

answered 2013-06-08 14:37:27 -0500

ramindk gravatar image

It's because Puppet autoloading assumes you're putting modules in ./modules/ rather than somewhere else. You can read more about it here, http://docs.puppetlabs.com/puppet/2.7/reference/modules_fundamentals.html

In your case I would recommend moving your custom Puppet code into modules/ and out of manifests/ so that autoloading works.

A couple of notes on import. It's going away, http://narvi.puppetlabs.com/issues/12929 , and it's likely to cause problems as your Puppet code becomes more complex. Some more detail on what import is really doing which is usually not what you expect here, http://docs.puppetlabs.com/puppet/2.7/reference/lang_import.html

edit flag offensive delete link more

Comments

My original idea was to not use imports at all as well, because they seem redundant. Also my setup at the moment is pretty basic since I have to manage ...(more)

Andrey Adamovich gravatar imageAndrey Adamovich ( 2013-06-09 05:35:32 -0500 )edit

For me it just seems confusing that autoloading works for "proper" modules, but does not work for "usual" manifests. I see that this is due to some legacy and backwards compatibility.

Andrey Adamovich gravatar imageAndrey Adamovich ( 2013-06-09 05:36:38 -0500 )edit
1

Using the manifests directory for anything other than assigning classes to nodes or setting global values (defaults, etc), is a (very old) legacy behavior. Using the module path for any ...(more)

supercow gravatar imagesupercow ( 2013-06-09 11:48:01 -0500 )edit
1

answered 2013-06-07 16:08:17 -0500

I found a way to import ALL *.pp files recursively from all child directories in a single import statement:

import '*/**/*.pp'

But still I'm a bit puzzled why autoloading can't work for site configuration in the same way it works for modules.

edit flag offensive delete link more

Comments

Just turn your admin classes into an admin module and be done with it.

Ancillas gravatar imageAncillas ( 2013-06-08 01:47:17 -0500 )edit

My modules directory contains some 3rd party modules, I just didn't want to mix 3rd party stuff with my stuff also taking into account that my setup is managing ...(more)

Andrey Adamovich gravatar imageAndrey Adamovich ( 2013-06-09 05:38:07 -0500 )edit

In any case, "import '*/**/*.pp'" is good enough for me at this point. Maybe when my setup grows I will convert some of the stuff into proper modules.

Andrey Adamovich gravatar imageAndrey Adamovich ( 2013-06-09 05:38:47 -0500 )edit
1

If you're looking to keep your 3rd party modules separate, create a second modulepath. In puppet.conf, do this (or something similar): modulepath = /etc/puppet/modules:/etc/puppet/internal_modules ...(more)

supercow gravatar imagesupercow ( 2013-06-09 11:45:59 -0500 )edit

I should also note that doing import like this will not always work as you expect it to. Sometimes you will need to restart the master for it to be ...(more)

supercow gravatar imagesupercow ( 2013-06-09 11:49:30 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2013-06-07 14:43:48 -0500

Seen: 396 times

Last updated: Jun 09 '13