I want to have a resource (or something) that I can use in several Puppet classes to cause a different resource to receive a list of the values defined in the source classes. I'm not sure how best to go about this.

More concretely:

I have a resource that creates a Nagios host definition. Each host definition includes one or more hostgroups.[0] I would like to define things generically so that the hostgroups for a host are determined dynamically based on the classes assigned to the Puppet node.

For example, let's say I have a node:

node www.example.com {
  include common_definitions
  include web_server
  include ftp_server

I would like to have something in the web_server and ftp_server classes that add relevant hostgroups to the Hagios definitions. Perhaps something like this:

class web_server {
  nagios::hostgroup { 'web-servers': hostname => $facts['hostname'] }
class ftp_server {
  nagios::hostgroup { 'ftp-servers': hostname => $facts['hostname'] }

Then the Nagios host definition would have something like this:

class nagios {
  $hostgroups = collect_exported_hostgroups_for($facts['hostname'])
  $hostgroup_string = join($hostgroups, ',')
  nagios:host_definition { $facts['hostname']:
    hostgroups => $hostgroup_string,

The key fact is that the nagios class doesn't know anything about what hostgroups to use until Puppet processes all of the node's other classes. This drives the process from the classes assigned to the node.

How can I do this?

[0] Technically, a host definition includes zero or more hostgroups, but my definitions will always have at least one hostgroup.


You probably want to use the datacat module. In fact, the README for it shows an example of manipulating Nagios hostgroups.

  • Yes, that handled things perfectly. I was able to have a main datacat_fragment resource with a hostgroups key in the data parameter. The value of that key is an array, so my nagios::hostgroup resource just wraps another datacat_fragment with the same hostgroups key and a different array. The datacat resource merges all of the arrays before handing them off to my file template. – asciiphil Apr 26 at 19:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.