0

I'm trying to get a service to notify another resource, i.e.

service { 'x': 
  notify    => Exec['y'],
}

Does anyone know what happens in the scenario where this notify would trigger? It seems like starting / stopping notifies the exec, but I can't seem to find any documentation of this.

1 Answers1

1

Does anyone know what happens in the scenario where this notify would trigger?

That particular notify should never trigger, because no properties of Service[x] are being managed.

There is nothing special about Service resources with regard to event signaling. Like resources of any other type, Service resources notify listeners if at least one of their managed properties is successfully changed to be in sync.

It seems like starting / stopping notifies the exec, but I can't seem to find any documentation of this.

If the service is initially stopped, but it is specified with ensure => running, then its ensure property is initially out of sync. Puppet brings that property into sync by starting the service. That constitutes a change to a managed property, so it generates an event. The general rules for this are documented in the "Relationships and Ordering" section of the Puppet language docs.

Not all attributes of a given resource declaration correspond managed properties, however. notify doesn't, for example. Attributes that do not have a persistent representation on the target system are called parameters. Because they have no persistent representation on the target, parameters can neither be out of sync nor be brought into sync, thus no event notification is associated with them The Puppet Resource Type Reference documents which attributes of each built-in type are properties. For example, the properties of Service resources are (only)

  • ensure
  • enable
  • flags

If you understand the distinction between properties and parameters, however, then it's usually obvious to which category any given attribute of any given type belongs.

John Bollinger
  • 160,171
  • 8
  • 81
  • 157
  • Thanks! does that mean something like: service { 'x': ensure => 'stopped' notify => Exec['y'], } would trigger when the ensure property changes? – Bob Markley Mar 13 '20 at 14:03
  • Yes, @AndyGu, with that declaration, if `Service[x]` were initially running and Puppet therefore stopped it, then `Exec[y]` would be notified. On the other hand, if `Service[x]` were initially stopped then Puppet would do nothing to it, so the `Exec` would not be notified. – John Bollinger Mar 14 '20 at 00:09