Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

How do I add handler to a defined type in puppet? For example, if I have:

define foo::bar ($baz) {

How can I have handler in foo::bar to handle something that contains

   notify => Foo::Bar['zippidy']


The handler would then run various Execs inside conditional logic when it receives a notification.

share|improve this question
up vote 7 down vote accepted

You can notify a defined resource that you've declared elsewhere in the catalog. How about an example?

CentOS system, httpd installed and stopped. Tested with Puppet 2.7.18

$ service httpd status
httpd is stopped

Here's an example manifest that contains an exec resource inside a defined resource type, a declaration of that defined resource type and a service resource that notifies that defined resource type.


define foo(){

   exec { "${name}_exec":
     command     => "echo hello ${name}",
     path        => '/bin:/usr/bin',
     refreshonly => true,
     logoutput   => true,


foo { 'bar': }

service { 'httpd':  
  ensure => running,  
  notify => Foo['bar'],  

When I apply this, the change of state in my httpd service resource triggers a notification to the Foo['bar'] resource. This notification will apply to any service or exec resources used inside the foo defined resource type.

$ puppet apply notify_defined_types.pp 
notice: /Stage[main]//Service[httpd]/ensure: ensure changed 'stopped' to 'running'
notice: /Stage[main]//Foo[bar]/Exec[bar_exec]/returns: hello bar
notice: /Stage[main]//Foo[bar]/Exec[bar_exec]: Triggered 'refresh' from 1 events
notice: Finished catalog run in 0.51 seconds

$ puppet apply notify_defined_types.pp 
notice: Finished catalog run in 0.38 seconds

Make sense? You just simply notify the resource that you declared. It'll trigger any exec or service resources exposed inside the defined resource type.

share|improve this answer
How do you do the inverse? Let's say I want the service to subscribe to Foo['bar']? Thanks – José F. Romaniello Jan 31 '15 at 17:56

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.