> How can I put in an update time in a template file? The problem I am
> running it to is this... Here is my file to update the timestamp
[...]
> The problem is that everytime puppet runs, it updates the time stamp.
> I only want it to update if there was an actual change to the content
> of the file
It would: there is no way for puppet to know that the changed content
of the template header is "unimportant", compared to other changes.
(Given this is an ERB template, there is no possible way to ever
determine that, unfortunately, and we can't hook template generation
well enough either.)
Your only solution would be to use some detail that did not ever
change: personally, I used the "Time Stamp" feature that Emacs offers
to statically update the timestamp when the file was saved, rather
than puppet.
If you wanted something more automatic I would probably look to VCS
keyword expansion, or to using the mtime of the template on the server
as the date, rather than the time that puppet expanded it.
Regards,
Daniel
--
✣ Daniel Pittman ✉ dan...@rimspace.net ☎ +61 401 155 707
♽ made with 100 percent post-consumer electrons
And how whould puppet know what you consider "an actual change". You
specified that the actual systemtime should be in the first line. Since
it's not true on your client, puppet will change the file (cause
checksums are different).
Or to put it this way: Imagine puppet distributed the file with an actual
timestamp. Someone now opens the file and change the timestamp in your
header. What do you expect puppet to do now?
If you really depend on your headerline consider the following: Don't
use Time.now but use something like
File.stat('/etc/puppet/modules/snmp/template/snmp.conf.erb').mtime.gmtime
[Maybe theres a way to address the filename from the template itself,
but I havent figured that out; __FILE__ and ARGV are not working]
This will be the same in every puppet run (except you changed the
template). But if you assign your class to a new node, the header will
still reflact the time when you changed the file on your master, and not
when puppet installed that file on your node.
-Stefan
Hi,
a template probably won't do this for you. Whenever puppet generates
your client's catalog, the template text is put into that. So if the
master generates the header, it will produce a different catalog each time.
The most simple thing would be for you to rely on the mtime instead.
This has some drawbacks, of course.
If the template is simple enough (and, unlike me, you know some ruby),
it may be feasible to write a simple plugin instead. That way, you *can*
limit header generation to times when there are actual changes.
HTH,
Felix
Feature request #4359 asks for a way that templates can get their own
name. It's not possible at the moment.
--apb (Alan Barrett)
I just had a look in parser/templatewrapper.rb and it turns out that we
can use a file accessor. At least the following template worked for me:
I am <%= file %>
The content of the file was then:
I am /etc/puppet/modules/test/templates/test.erb
I also updated your feature request.
-Stefan