Write current date to template, when it changes


#1

Hi,

I want to write a cookbook for a bind. My problem is, that I don’t know how I can generate the timestamp (serial) without changing the template everytime.

$TTL 86400 ; TTL: 1 day
@ IN SOA hostname.domainname.
hostmaster.domainname. (
201203061523 ; Serial (last changed date and time)
3h ; Refresh
15 ; Retry
1w ; Expire
3h ; Minimum
)
I want to generate the timestamp with the following ruby code: Time.new.strftime("%Y%m%d%H%M")

So I only want to write the current time to the template if the template changes.

How can I do that?

NEU: FreePhone 3-fach-Flat mit kostenlosem Smartphone!
Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a


#2

On Tue, Mar 6, 2012 at 9:29 AM, SharenZ@gmx.at wrote:

I want to write a cookbook for a bind. My problem is, that I don’t know how I can generate the timestamp (serial) without changing the template everytime.

The template provider renders the template to disk and then compares
it with the existing file using a checksum. Thus you can’t easily do
this.

One solution could be to set the time field in the template to a
static placeholder like TIME_BASED_SERIAL and set the template path to
a temporary directory near the real file. Then create an execute or
ruby_block resource with its default action set to nothing. Have it
replace that value with a generated time and move the file into the
production location. Notify this resource from the template resource
and then notify the reload of the service with this one.

template “/etc/bind/staging/foo.conf” do
source "foo.conf.erb"
owner "root"
group "root"
notifies :run, “execute[bind-install-foo]”, :immediately
end

execute “bind-install-foo” do
command “sed -ie
s/TIME_BASED_SERIAL/#{Time.new.strftime(”%Y%m%d%H%M")}/
/etc/bind/stanging/foo.conf && mv /etc/bind/staging/foo.conf
/etc/bind/foo.conf"
action :nothing
notifies :reload “service[named]”, :delayed
end

service “named” do
action [ :start, :enabled]
end

Bryan


#3

On Thu, Mar 8, 2012 at 10:19 AM, Bryan McLellan btm@loftninjas.org wrote:

On Tue, Mar 6, 2012 at 9:29 AM, SharenZ@gmx.at wrote:

I want to write a cookbook for a bind. My problem is, that I don’t know how I can generate the timestamp (serial) without changing the template everytime.

The template provider renders the template to disk and then compares
it with the existing file using a checksum. Thus you can’t easily do
this.

One solution could be to set the time field in the template to a
static placeholder like TIME_BASED_SERIAL and set the template path to
a temporary directory near the real file. Then create an execute or
ruby_block resource with its default action set to nothing. Have it
replace that value with a generated time and move the file into the
production location. Notify this resource from the template resource
and then notify the reload of the service with this one.

> Bryan

I wonder if it’s not time for a new convenience construct that
understands incrementing counters like that. Zone serials are the only
place I can think of immediately where this is helpful but I’m sure
others have more use cases.

Maybe something even more generic. Do notifications for templates
work? The end result here (and I’m typing this for MY benefit to think
about it) is that the template construct either needs to understand
subtleties around content vs. header? This might just need to be an
LWRP that tracks the serial via a data bag somewhere?


#4

I solved this problem initially in my local bind cookbook by using
$INCLUDE in the bind zone file, and having the included records
template notify the parent zone template. In that zone template I
simply do a time stamp for serial. I then ended up abandoning this
method and writing an lwrp for nsupdate cause I wanted to be able to
add records to a zone that’s getting dhcp updates.

I am cleaning up this cookbook for release, and hope to have something
out next week If you’re interested.

On Thu, Mar 8, 2012 at 10:19 AM, Bryan McLellan btm@loftninjas.org wrote:

On Tue, Mar 6, 2012 at 9:29 AM, SharenZ@gmx.at wrote:

I want to write a cookbook for a bind. My problem is, that I don’t know how I can generate the timestamp (serial) without changing the template everytime.

The template provider renders the template to disk and then compares
it with the existing file using a checksum. Thus you can’t easily do
this.

One solution could be to set the time field in the template to a
static placeholder like TIME_BASED_SERIAL and set the template path to
a temporary directory near the real file. Then create an execute or
ruby_block resource with its default action set to nothing. Have it
replace that value with a generated time and move the file into the
production location. Notify this resource from the template resource
and then notify the reload of the service with this one.

> Bryan

I wonder if it’s not time for a new convenience construct that
understands incrementing counters like that. Zone serials are the only
place I can think of immediately where this is helpful but I’m sure
others have more use cases.

Maybe something even more generic. Do notifications for templates
work? The end result here (and I’m typing this for MY benefit to think
about it) is that the template construct either needs to understand
subtleties around content vs. header? This might just need to be an
LWRP that tracks the serial via a data bag somewhere?


#5

Hi all,

In case anybody has this problem:

The manual: http://wiki.opscode.com/display/chef/Installing+Chef+Server+Manually states that:
gpg --keyserver keys.gnupg.net --recv-keys 83EF826A

Yet in the chef-server cookbook https://github.com/cookbooks/gecode/blob/qa/recipes/default.rb , I’ve seen it use:

key "2940ABA983EF826A"
keyserver "pgpkeys.mit.edu"

I have MAJOR problems with both of these. pgpkeys.mit.edu is just far too frequently out of capacity, and keys.gnupg.net for some weird reason only works 50% of the time for me (randomly, so I’m guessing DNS roundrobining isnt working or something). Really frustrating for automating chef-servers.

I found this solution works fine and consistently however:

  key "83EF826A"
  keyserver "pool.sks-keyservers.net"

This seems to be a pool of keyservers around the web which I’ve never had problems with. Maybe it helps someone