On Wednesday, May 16, 2018 at 10:12:54 PM UTC-5, 程伟 wrote: > > Hi,everyone! > I want to create a signal file when some particular file changes. I find > a syntax called *notify* in puppet docs could realize my need. So I tried > like this: > > file {'target_file': > ensure => 'present', > source => 'puppet:///files/target_file', > path => '/opt/target_file', > notify => File['signal_file'], > } > > file {'signal_file': > ensure => 'present', > path => '/opt/signal/signal_file', > subscribe => File['target_file'], > } > > However, I tried it many times, and found that even if target_file has > existed and not changed, signal_file still created. It's not my purpose. > Can anyone tell me if I miss something? >
Yes, you're missing something. When Puppet creates or modifies a resource A, every resource that A notifies and every resource that subscribes to A receives an "*event*" (either notify or subscribe is sufficient; you don't need both). A resource that receives an event from any source will attempt to "*refresh" *some time after it is synced, but a refresh is separate from the preceding sync, and for most resource types it is a no-op. The most common uses of this feature are in conjunction with Service and Exec resources, which have meaningful refresh behavior. Other than that, 'notify' has the same semantics as 'before', and 'subscribe' has the same semantics as 'require', so if A fails, those resources it notifies and those that subscribe to it will be skipped. As long as A succeeds, however, whether that involves any changes or not, those other resources will be applied. In your particular case, then, you could change your 'notify' to 'before' and your 'subscribe' to 'require' without discernible effect on Puppet's behavior: it will attempt to apply File[signal_file] regardless of whether it receives an event, so long as File[target_file] is successfully synced first. It looks like you can achieve your objective with an Exec instead: file { 'target_file': ensure => 'present', source => 'puppet:///files/target_file', path => '/opt/target_file', } ~> exec { 'create signal file': command => '/bin/touch /opt/signal/signal_file', refreshonly => true, } Note that the '~>' operator there has the same effect as either your notify or your subscribe would have, and that the Exec is marked as refreshonly (a feature specific to the Exec resource type) so that its designated command is run only when that resource is refreshed, not when it is synced. 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/dbe0a810-624f-4b4b-baec-8e2e592a9617%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.