Puppet Class Dependencies within Modules

puppetsensu

Currently, I am writing a puppet module for managing my sensu configuration.

Have split the whole thing into several classes and put them into their respective files in the sensu "manifests" directory:

sensu::common          (common.pp)
sensu::common::package (common/package.pp)
sensu::common::config  (common/config.pp)
sensu::server          (server.pp)
sensu::server::config  (server/config.pp)

In my server.pp, I have the following

class sensu::server {
  include sensu::common
  include sensu::server::config

  Class['sensu::common'] -> Class['sensu::server::config']
}

And the nodes.pp looks like this:

class role_monitoring_server {
  $my_role = 'monitoring_server'
  ...
  include sensu::server
}

node my_cool_server {
  include role_monitoring_server
}

As most of you might have guessed, I have trouble with the class dependency in server.pp:

Class['sensu::common'] -> Class['sensu::server::config']

just does not work. The class sensu::server::config needs to place a file in a directory, that will only be created by sensu::common. The thing is, that sensu::server::config will always be applied before sensu::commonand not after as expected.

What do I miss? There are so many questions out there on the web but I just don't find an answer, since I don't know what to look for.

Best Answer

You're creating a dependency relationship with the sensu::common class, but there's no implicit dependency relationship between sensu::common and its "children", package and config. So, unless your config looks otherwise (I'm assuming the sensu::common class is just a couple include lines?) those are still free to be applied at any time in relation to the sensu::server::config class.

You'll probably want to build the relationship with the class that contains the resources that you need; you're effectively creating a require relationship each resource in one class to each resource in the other (whichever one of these is needed, or both):

Class['sensu::common::package'] -> Class['sensu::server::config']
Class['sensu::common::config'] -> Class['sensu::server::config']
Related Topic