On Monday, July 6, 2015 at 8:43:33 AM UTC-5, Jonathan Gazeley wrote: > > On 06/07/15 14:26, Peter Meier wrote: > > -----BEGIN PGP SIGNED MESSAGE----- > > Hash: SHA1 > > > >> Notify on its own is no good, since if the exec fails, the service > >> gets restarted anyway. > >> > >> Require on its own is no good, since the exec runs every time. > >> > >> Is there some way to combine the two? > > The problem is that a notify includes a before relationship, which > > means that the service resource is always being managed *before* the > > config test happens. What you want is the following: > > Hi Pete, > > Thanks for your detailed response. At my site, the DHCP config is partly > written out by a Forge module, partly generated by a script from a > database and partly deployed from a git repo where it is edited by > humans. So it seems a bit messy to get all of these resources to notify > the config test and the service. > >
You can always have the config-test resource 'subscribe' to the various data source resources instead of having the data sources 'notify' the exec. The effects are identical. Likewise, you may either have the config-test resource 'notify' the service or have the service 'subscribe' to the config-test resource. It seems pretty clean to me to put all these relationships on the config test, as that way you can freely modify or even remove the config test without changing anything else. The ultimate data sources can notify the service directly if you wish; that will not prevent the config test being interposed between and serving to gate the restart. If you want the test to be performed only when one of the config sources is modified (by Puppet) then set it to be 'refreshonly'. You cannot hook the test so tightly to the service that it is automatically run before the service is refreshed, without regard to the reason for the refresh. You could, however, wrap Exec and Service together into a defined type, to serve as a stand-in for the bare Service resource, so that any event received by the defined type instance triggers the test before the service is restarted: define mymodule::checked_dhcpd( $test_command = '/bin/true', # service properties ... ) { exec { 'dhcpd-config-test': command => $test_command, refreshonly => true } ~> service { 'dhcpd': # ... } } That does not protect you from resources notifying the Service directly, but it will do what you want as long as they notify only the defined-type instance (which alternatively may itself subscribe to any resource of interest). John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/b8522a1d-3a46-4a99-9b72-f96a04bb3f1d%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.