3

Let's say I have this manifest bit in Puppet:

file { "/whatever/file":
    notify => Exec["some_script"]
}

Is there a way to get "/whatever/file" from "some_script"? Or in other words, how can I get the name of a resource that notifies another from the notified one?

The use case is this: we're using git to track changes in /etc, and I'd like Puppet to auto-commit the files that I modify from a manifest. For that, I will use a "exec" resource that is notified by each "file" resource that modifies files in /etc. But I need to know which file was modified to commit only that, and avoid doing a blind "commit -a".

Of course, if there's a better way to do this, I'm open to suggestions.

Zelda
  • 6,262
  • 1
  • 23
  • 28
rsuarez
  • 902

1 Answers1

1

While you could create a parameterized class and then pass an array of file names into that class to use as the file name, I would suggest against it.

Templates would be a much better approach.

file {'/etc/sshd/conf':
   content => template('foo/ssh-conf.erb'),
}

Then when you need to make a change, you edit the ssh-conf.erb template and it is pushed out to all the machines.

In general, exec statements in puppet should be used as a last resort. File templates and augeaus resources are much simpler and are just as powerful.

Also, I would suggest against scripts managing files in git.

spuder
  • 18,053