execute on change

32 views
Skip to first unread message

nike....@gmail.com

unread,
Nov 19, 2013, 3:40:54 AM11/19/13
to puppe...@googlegroups.com
Hi!
I need to create manifest that creates file and run some command on it's change. I thought that I can do it with subscribe and notify statements, but I can't. Can someone give me example of such manifest?
I tried using manifest like this, and it always displays notify message, despite the fact that file has not changed
        file { '/tmp/test':
                ensure => present,
                content => "Hello",
        }
       notify {'after':
               message => "File created",
               subscribe => File['/tmp/test/'],
       }
File['/tmp/test'] ~> Notify['after']

Justin Lambert

unread,
Nov 19, 2013, 6:12:36 AM11/19/13
to puppe...@googlegroups.com
If you’re trying to run an exec, you can do this:

file { ‘/tmp/test’:
ensure  => present,
content => ‘Hello’,
notify    => Exec[‘after’],
}

exec { ‘after’:
command   => ‘/bin/echo Created’,
        refreshonly => true,
}

subscribe on the exec vs notify on the file works as well as does the chaining arrow.  To me, notify is easier to read but you can mix and match as well.  I think the refreshonly parameter is only available on the exec resource, but you can also notify other resources such as services which will restart the service.  There are some resources it doesn’t make sense to notify such as files since the actual file is being validated/updated every puppet run regardless of what is happening with any other resource.

--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/a839b7ee-c1bc-40fb-a2a1-b56d47b1d415%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

John Bollinger

unread,
Nov 19, 2013, 1:21:09 PM11/19/13
to puppe...@googlegroups.com


Only a few resource types, not including Notify, actually do anything in response to events received from modified resources, and that is above and beyond their ordinary synchronization behavior.  Of those, only Exec (that I am aware of) has a mechanism for altogether suppressing its ordinary sync behavior.  Other than for Execs, you cannot condition whether a resource is synced on whether another resource is transitioned from out-of-sync to synchronized.


John

nike....@gmail.com

unread,
Nov 20, 2013, 3:28:31 AM11/20/13
to puppe...@googlegroups.com
Thanks! That is exactly I need!

вторник, 19 ноября 2013 г., 20:12:36 UTC+9 пользователь Justin Lambert написал:
Reply all
Reply to author
Forward
0 new messages