Ask Your Question

Puppet class orders break using defines

asked 2015-08-19 10:23:49 -0500

rjinski gravatar image

I have a level of dependency in the order of modules being applied:

class build() {
    # define order
    Class['base'] -> Class['config'] -> Class['app'] -> Class['sso']

    class { 'base' : ... }
    class { 'config' : ... }
    # etc

class base::init.pp () {
    class { 'base::prereqs' : ... }
    class { 'base::worker' : 
        require => Class['base::prereqs']

# etc etc

The error occurs when base::prereqs has:

define base::prereqs::file () { ... }

class base::prereqs () {
    $files = [ 'file_name', ... ]
    base::prereqs::file { $files : }

The desired order is base::init --> base::prereqs --> base::worker --> config::init --> config::prepreqs --> config::worker --> app::init ...

However the actual order using a define becomes...

base::init --> base::prereqs (except resources created in the define) --> config::init --> config::prereqs --> ... --> base:prepreqs (resources created by define) --> base::worker

The ordering inside base is consistent but the level above in order does not seem to know that resources have been added inside of prereqs and considers base complete.

Any help?

Puppet v3.6.2 (Puppet Enterprise 3.3.2)

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2016-04-09 18:39:49 -0500

DarylW gravatar image

I believe that you need to use 'contains' or the 'anchor pattern' to make sure your classes called via classes actually resolve in the order you want. Unless you use contains or the anchor pattern, it only means that the enclosing class has 'finished', not all of the classes inside of it.

However, unlike resources, Puppet does not automatically contain classes when they are declared inside another class. This is because classes may be declared in several places via include and similar functions. Most of these places shouldn’t contain the class, and trying to contain it everywhere would cause huge problems.

Instead, you must manually contain any classes that need to be contained.

a define is treated as a resource, so everything declared in it is grouped with it, but a class does not automatically contain the other classes inside of it, since it doesn't make a distinction between an "include 'myclass'" and a "class{'myclass:}".

If you have any more questions about this (rightfully confusing), let us know!

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: 2015-08-19 10:23:49 -0500

Seen: 299 times

Last updated: Apr 09 '16