Ask Your Question

another kind of error "Could not find class"

asked 2017-02-25 10:45:36 -0500

zxkydq gravatar image

updated 2017-02-27 13:56:20 -0500

DarylW gravatar image

i use "puppet apply" to test the code:

module name: zx

file /etc/puppet/modules/test/manifests/init.pp:

class zx {
include zx::install
include zx

file /etc/puppet/modules/test/manifests/install.pp:

class zx::install {
(some resource code)

and then, i use "puppet apply -tv --noop /etc/puppet/modules/zx/manifests/init.pp", and error : Error: Could not find class zx::install for xxxx on node xxxx

i want to know why??? because i use "puppet apply modules/zx/test/init.pp", it works. and i copy modules/zx/manifests/init.pp to another dir, then "puppet apply", it works too. that is very strange.

edit retag flag offensive close merge delete


Either use resource like class inclusion, or a `include` statement: I guess the --test flag enables the automatic module lookup strategy. Only without the flag a literally specified gets applied (w/o searching it).

Kai Burghardt gravatar imageKai Burghardt ( 2017-02-25 18:10:22 -0500 )edit

Also make sure your module is in a module directory environment that puppet can find. I.E. /etc/puppetlabs/puppet/code/production/...

puser gravatar imagepuser ( 2017-02-27 07:21:23 -0500 )edit

It looks like you have it in a folder on your modulepath named 'test' but you want the module to be named 'zx'. the name of the folder needs to match the name of the class, otherwise the classloader cannot find it. if you do `mv /etc/puppet/modules/test/ /etc/puppet/modules/zx` it should be found

DarylW gravatar imageDarylW ( 2017-02-27 13:58:16 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2017-03-01 07:06:00 -0500

rnelson0 gravatar image

You are trying to apply a puppet class as a manifest. That is not how classes are designed to be used. Each class should contain only the class <name> { ... } code, no code outside of that block (i.e. no include <name> as yours has). In addition, there is an module layout that puppet expects to use with its autoloader. To include the zx class, you want to include that through a site manifest manifests/site.pp or preferably through a classifier and/or a role class. For testing purposes, it is simpler to use the site manifest.

Create /etc/puppet/manifests/site.pp with the content:

node default { include zx }

Next, rename the path /etc/puppet/modules/test to /etc/puppet/modules/zx - the autoloader requires the module path to match the module name, and test != zx.

Finally, call puppet apply and tell it where to find the site manifest and the modules. This will allow the autoloader to discover all the module classes so that the class zx::install will be discovered. The modulepath and option is what you care about here.

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

This should work. If it does not, try puppet module list --modulepath=/etc/puppet/modules and see what errors occur. It SHOULD find the zx module and no other.

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools


Asked: 2017-02-25 10:45:36 -0500

Seen: 63 times

Last updated: Mar 01