Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
  • I've got some servers (www, etc)
  • I've got a monitoring system
  • If a machine has to be apache monitored it needs some files to be installed.

So I've got a apache module (which installs Apache) and I'm writing a monitoring module. This monitoring module will copy the needed files, only if the apache package is installed (or if the apache module is defined, or something like that). Same for the mysql package, etc.

Is the above design a good idea? What would be the best way for this kind of dependency?

share|improve this question
up vote 0 down vote accepted

In your extdata, create a variable that defines whether or not a server needs to be monitored. Here's an example of enabling monitoring by default and disabling it for a specific server.





In your class for each service, lookup whether monitoring is enabled. If it is, include the class responsible for monitoring that service. This could look something like

class apache {

  # Manage your apache setup here

  if extlookup("use_monitoring") == 'true' {
    include monitoring::apache


class monitoring::apache {
  # Manage your apache monitoring setup here

Update: When I first read your question, I thought you were asking for a way to enable monitoring on some but not all of your Apache servers. If you want to monitor all of them, you don't even need to bother with extlookup. Just split up your monitoring class into service-specific ones and include them in the class for the service.

share|improve this answer

In your apache class you could define a variable, that you use in a test to see if you should deliver your monitoring file or not.

class apache {
  $apacheconfigured = true;

class monitor {
  if $apache::apacheconfigured {
    file {'blah': ... }
share|improve this answer
Voted up because I used your answer as well. – SamK Nov 7 '11 at 11:33
Well, did not work: Could not match ${ntp::nrpe_monitoring} – SamK Nov 7 '11 at 15:17
It is odd that it didn't work for you, I am using all over the place in my configuration. – Zoredache Nov 7 '11 at 16:46
good point. I figured that out afterwards. – SamK Nov 7 '11 at 16:50

You need either virtual resources or custom facts. If the configuration of one host will change the configuration of another, then you need exported resources. I have all these things, actually. Here's a sampling.

Virtual Resources

On the Monitoring class:

@file { '/path/to/apache/monitoring/conf': 
    ensure => file,
    source => 'puppet:///modules/monitoring/apache.conf',
    tag    => 'apache-extras',

On the Apache class:

File <| tag == 'apache-extras' |>
Exec <| tag == 'apache-extras' |>

Custom Facts

Declare a fact like this, and put it in the appropriate place (see link above):

# apache2.rb
Facter.add("apache2") do
        setcode do
                %x{/usr/bin/test -x /etc/init.d/apache2 && /bin/echo yes || /bin/echo no}.chomp

On the Monitoring class, use:

if $apache2 == 'yes'   {
   # include configuration for apache

Exported Resources

On the Apache class, included in the Apache server:

@@exec { "config-web $fqdn": 
            tag => "monitoring-server", 

On the Monitoring class, included in the Monitoring server:

<<| tag == 'monitoring-server' |>>
share|improve this answer

Why don't just require => Package['apache'] on resources in monitoring module? If there's apache and monitoring classes added to node, files that depends on apache would be installed iff it's installed succesfully. If it does not (e.g. package failed to install, or apache module is not added to node, monitoring class would just fail).

Or if you don't want it to fail, you could use something like following:

if defined(Package['apacge']) {
    file {...}
    <and so on>
share|improve this answer
I don't want the monitoring class to fail because the monitoring class will also copy files for other services (sql, etc). Question updated for better understanding. Maybe I could test if the apache class is defined? – SamK Nov 4 '11 at 16:13
ok, answer updated – rvs Nov 4 '11 at 17:57
Your updated solution won't work reliably; you can't guarantee that the puppetmaster will process the apache class before the monitoring class. See the explanation at – sciurus Nov 4 '11 at 19:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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