Re: [Puppet Users] Update time in template file.

Stefan Schulte
2010-12-19T22:41:01Z

Hi

On Sun, Dec 19, 2010 at 01:16:34PM -0800, rjl wrote:
> Hi all,
> 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
>
> snmp.conf.erb
>
> # HEADER: [ <%= Time.now.gmtime %> ] Modified by puppet.
> defVersion 2c
> devCommunity somecommunity
>
>
> 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

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