- From: Bryan McLellan <
>
- To:
- Subject: [chef] Re: [Chef] Write current date to template, when it changes
- Date: Thu, 8 Mar 2012 10:19:42 -0500
On Tue, Mar 6, 2012 at 9:29 AM,
<
>
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
Archive powered by MHonArc 2.6.16.