Module/Class ordering with contain()

57 views
Skip to first unread message

lupin...@gmail.com

unread,
Dec 9, 2014, 8:22:35 AM12/9/14
to puppet...@googlegroups.com

Hi,

 I'm struggling with Ordering/Relationship between modules classes, I used this as my guide http://puppetlabs.com/blog/class-containment-puppet but somehow still can't make it work correctly.

So I have

tail  ../../role/manifests/lbserver.pp
class role::lbserver {

  include profile::model
  include profile::data
  include profile::modadp
  Class['::profile::model'   ] ->
  Class['::profile::data'] ->
  Class['::profile::modadp']
}


root@puppet-m:/etc/puppetlabs/puppet/environments/development/modules/profile/manifests# cat model.pp
class profile::model {
  contain '::spss_model'
}
root@puppet-m:/etc/puppetlabs/puppet/environments/development/modules/profile/manifests# cat data.pp
class profile::data {
  contain '::mod_data'
}
root@puppet-m:/etc/puppetlabs/puppet/environments/development/modules/profile/manifests# cat model.pp
class profile::model {
  contain '::mod_model'
}
root@puppet-m:/etc/puppetlabs/puppet/environments/development/modules/profile/manifests# cat modadp.pp
class profile::modadp {
  contain '::mod_modadp'
}
I received the following error.

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Could not find class ::mod_modadp for node x.x.x.x

Thanks in advance.

lupin...@gmail.com

unread,
Dec 9, 2014, 5:06:14 PM12/9/14
to puppet...@googlegroups.com
Hi,

The initial error was a typo, but the Order of execution of class is not being achieve, is this possible?

Cheers

jcbollinger

unread,
Dec 10, 2014, 2:20:25 PM12/10/14
to puppet...@googlegroups.com


On Tuesday, December 9, 2014 11:06:14 AM UTC-6, lupin...@gmail.com wrote:
Hi,

The initial error was a typo, but the Order of execution of class is not being achieve, is this possible?



Whatever behavior you observe is evidently possible, because you observe it.  Whether it is consistent with the manifest fragments you presented is cannot be judged without knowing at least what that order actually is.


John

Mark Rosedale

unread,
Dec 10, 2014, 3:17:25 PM12/10/14
to puppet...@googlegroups.com
I generally don't use includes. I do class declarations. If you need to order classes within a module I tend to use the before or require and subscribe for ordering. So for instance for module foo if I need class first to run first and two to run second I could do either of the following. 

class foo {
  class {'first':
    before => Class['two']
  }
  class {'two':}
}

Or 
class foo {
  class {'first':  }
  class {'two':
    require => Class['first']
  }  
}

Require is good if you had say a config class that requires a package be installed first. If you need a module to run before a second module I'll typically chaining (and note you could just as easily do this inside your init file for class ordering within a module)

class runafter {
  Class['runbefore'] -> Class['runafter']
  class {'foo': }
  class {'bar': }
}

In this case module runbefore will be run before module runafter. Note that this assumes that you declare these modules to the node as class declarations (ie node foo { class {'runbefore': } }. Also note that now runafter depends upon runbefore. IOW if you fail to declare runbefore then your catalog will fail to compile if you use runafter. And the first example declared with this latter method would look like this. 

class foo {
  Class['first']->Class['two']
  class {'first':  }
  class {'two': }
}

Again I don't use the includes so I don't know how that changes the equation, but you can do most, if not all, of your ordering with either of these two methods. For more information check out this link.  And just to throw it out there if you have a module that needs to be run before all other modules (like a yum module or apt module) you can set run stages, but avoid this for all but the broadest of cases like the ones already mentioned. 

Felix Frank

unread,
Dec 10, 2014, 3:29:22 PM12/10/14
to puppet...@googlegroups.com
On 12/10/2014 04:17 PM, Mark Rosedale wrote:
> class foo {
> Class['first']->Class['two']
> class {'first': }
> class {'two': }
> }

Well, this should generally be avoided. It deprives you of the ability
to declare either 'first' or 'two' anywhere else in the manifest.

include really is the better option.

As for contain, that is indeed necessary. The ordering you present will
work for resources that are declared in the body of 'first' and 'two',
but not transcend to classes that either of them declares in turn
(*unless* this is done using contain).

Hope that clears things up a little.

Cheers,
Felix

jcbollinger

unread,
Dec 11, 2014, 2:29:15 PM12/11/14
to puppet...@googlegroups.com
I love it when Felix says things so I don't have to do.


John

Reply all
Reply to author
Forward
0 new messages