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 Nagios 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.