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 Thanks in advace. rjl -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On Mon, Dec 20, 2010 at 08:16, rjl <rjlindal@gmail.com> wrote:> 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 fileIt 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 ✉ daniel@rimspace.net ☎ +61 401 155 707 ♽ made with 100 percent post-consumer electrons -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
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 fileAnd 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
On 12/19/2010 10:16 PM, 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 > > Thanks in advace. > > rjlHi, 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 -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Thanks to everyone for all of your input. It was very helpful. I like Felix''s suggestion about writing a plugin. rjl On Dec 20, 5:03 am, Felix Frank <felix.fr...@alumni.tu-berlin.de> wrote:> On 12/19/2010 10:16 PM, 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 > > > Thanks in advace. > > > rjl > > 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-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On Sun, 19 Dec 2010, Stefan Schulte wrote:> 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]Feature request #4359 asks for a way that templates can get their own name. It''s not possible at the moment. --apb (Alan Barrett) -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On Wed, Dec 22, 2010 at 08:55:21AM +0200, Alan Barrett wrote:> On Sun, 19 Dec 2010, Stefan Schulte wrote: > > 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] > > Feature request #4359 asks for a way that templates can get their own > name. It''s not possible at the moment.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