Post details: Using post-change commands in puppet manifests

06/21/06

Permalink 05:06:13 pm, Categories: Configuration management, Puppet, 134 words  

Using post-change commands in puppet manifests

Sometimes it is necessary in a puppet manifest to run a command with exec every time puppet changes a file. The subscribe metaparameter is ideal for this purpose, since it causes the dependent element to be executed whenever the referenced element changes — with the small caveat that the dependent element will also be executed when it sees a need to run by itself. In the case of exec that means always, unless execution is suppressed with onlyif. Therefore, to run a command every time a file changes, but not when that file hasn't been changed, the manifest must contain something like:

file { "/tmp/foo.txt":
  source => "/tmp/bar.txt"
}

exec { subscribe-echo:
  command => "/bin/echo subscribe triggered",
  logoutput => true,
  onlyif => "/bin/false",
  subscribe => file["/tmp/foo.txt"]
}

Comments:

Comment from: lutter [Member]
Eric-Olivier Lamey emailed to say that Puppet's exec type has a refreshonly attribute for excactly this purpose, so that the exec above can also be written as
exec { subscribe-echo:
  command => "/bin/echo subscribe triggered",
  logoutput => true,
  refreshonly => true,
  subscribe => file["/tmp/foo.txt"]
}
Permalink 09/05/06 @ 12:08

Comments are closed for this post.

Search

Syndicate this blog XML

What is RSS?

Misc

powered by
b2evolution