Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Puppet cannot find class

Tags:

puppet

Hi I'm new to puppet and I'm trying to make a test class, but when I run puppet apply-t I get error Error: Evaluation Error: Error while evaluating a Function Call, Could not find class ::heroes for under my test directory I have

.
├── examples
│   ├── init.pp
│   └── superhero.pp
└── manifests
    ├── init.pp
    └── superhero.pp

2 directories, 4 files

in my superhero.pp under manifest the code reads

class heroes {
    user { 'thor':
        ensure => present,
    }
}

in my superhero.pp under example the code reads

include heroes

Not sure why when I run puppet apply --noop superheroes.pp under examples that error shows up?

Here is my complete tree under modules

├── hosts
│   ├── examples
│   │   └── init.pp
│   └── manifests
│       └── init.pp
├── nginx
│   ├── examples
│   │   └── init.pp
│   ├── files
│   │   ├── default.conf
│   │   ├── index.html
│   │   └── nginx.conf
│   ├── index.html
│   └── manifests
│       ├── index.html
│       └── init.pp
├── test
│   ├── examples
│   │   ├── admins.pp
│   │   ├── init.pp
│   │   └── superhero.pp
│   └── manifests
│       ├── admins.pp
│       ├── init.pp
│       └── superhero.pp
└── users
├── examples
│   ├── admins.pp
│   └── init.pp
└── manifests
    ├── admins.pp
    └── init.pp
like image 563
jumpman8947 Avatar asked Dec 25 '22 16:12

jumpman8947


1 Answers

I think there may be two problems

  1. First is that when running puppet apply superheroes.pp in the examples directory, it doesn't know where to look for other modules (like heroes you include). To know where to look for modules, you need to give it a modulepath:

    puppet apply --modulepath=/path/to/modules --noop superhero.pp

  2. The other problem is the location of heroes class that you state is located in test/manifests/superhero.pp. The rules for where Puppet is trying to find classes are described here and here. Unless you're doing something less usual such as defining a class inside another class, puppet will use the following rules to locate the class:

    1. The first segment (segments are separated by ::) identifies module.
    2. If there is only one segment, file name is init.pp, otherwise file name is the last segment with .pp extension
    3. The segments in between denote subdirectories under manifests directory.
    4. The path where puppet will look is

      <modulepath>/<module name>/manifests/<subdirectories>.../<file name>.pp
      

    Here is an example from the documentation:

        == class name ==        == path ==
        apache                  <module path>/apache/manifests/init.pp
        apache::mod             <module path>/apache/manifests/mod.pp
        apache::mod::passenger  <module path>/apache/manifests/mod/passenger.pp
    

Returning back to your question: Upon include heroes, puppet will look in <modulepath>/heroes/manifests/init.pp. Conversely, to make puppet look in test/manifests/superhero.pp, you would need to include class test::superhero.

like image 73
Mifeet Avatar answered Jan 31 '23 08:01

Mifeet