Comparing the checksum of a cookbook_file in an non cookbook_file resource

Hi All,

We have a deployment scenario where we are deploying a war to a Tomcat server, and if a developer or ops person is in the exploded war directory at the time, tomcat fails to redeploy the war file. We are not using the application cookbook.

What I would like to do is add a file and directory resource to delete the war file and exploded war directory if the war file’s checksum has changed prior to the cookbook_file line. I am assuming that the cookbook_file resource always uses the checksum by default. Recipe snippet below:

#Caching

file “#{node[:tomcat][:webapp_dir]}/perc-caching.war” do

action :delete

only_if [checksum of new cookbook file doesn’t match installed cookbook file]

end

directory “#{node[:tomcat][:webapp_dir]}/perc-caching” do

action :delete

recursive true

only_if [checksum of new cookbook file doesn’t match installed cookbook file]

end

cookbook_file “#{node[:tomcat][:webapp_dir]}/perc-caching.war” do

source "perc-caching.war"

backup false

owner "#{node[:tomcat][:user]}"

group "#{node[:tomcat][:group]}"

only_if [is this implied by the cookbook_file resource?]

end

Is there a way to get the checksum of the cookbook_file that is currently installed and comparing it to the checksum of the new cookbook file so that the delete actions on the file and directory resources only run when the file has changed?

Any help,tips, comments, appreciated.

Thanks!

Nate Chadwick Percussion Software

(O) 781-835-1356 | nate_chadwick@percussion.com

See for yourself what all the fuss is about—watch a demo now!

On Monday, July 23, 2012 at 8:15 AM, nate_chadwick@percussion.com wrote:

Hi All,

We have a deployment scenario where we are deploying a war to a Tomcat server, and if a developer or ops person is in the exploded war directory at the time, tomcat fails to redeploy the war file. We are not using the application cookbook.

What I would like to do is add a file and directory resource to delete the war file and exploded war directory if the war file's checksum has changed prior to the cookbook_file line. I am assuming that the cookbook_file resource always uses the checksum by default. Recipe snippet below:

#Caching
file "#{node[:tomcat][:webapp_dir]}/perc-caching.war" do
action :delete
only_if [checksum of new cookbook file doesn't match installed cookbook file]
end

directory "#{node[:tomcat][:webapp_dir]}/perc-caching" do
action :delete
recursive true
only_if [checksum of new cookbook file doesn't match installed cookbook file]
end

cookbook_file "#{node[:tomcat][:webapp_dir]}/perc-caching.war" do
source "perc-caching.war"
backup false
owner "#{node[:tomcat][:user]}"
group "#{node[:tomcat][:group]}"
only_if [is this implied by the cookbook_file resource?]
end

Is there a way to get the checksum of the cookbook_file that is currently installed and comparing it to the checksum of the new cookbook file so that the delete actions on the file and directory resources only run when the file has changed?

Any help,tips, comments, appreciated.

Thanks!

Nate Chadwick • Percussion Software
(O) 781-835-1356 | nate_chadwick@percussion.com (mailto:nate_chadwick@percussion.com)

You want to chain the resources together with notifications:

http://wiki.opscode.com/display/chef/Resources#Resources-Notifications

Then you probably also want to use action :nothing on the other resources.

--
Dan DeLeo

Makes sense. Thanks, will give this a try.

-n

-----Daniel DeLeo <ddeleo@kallistec.com> wrote: -----To: chef@lists.opscode.com

From: Daniel DeLeo

Sent by: Daniel DeLeo

Date: 07/23/2012 02:38PM

Subject: [chef] Re: Comparing the checksum of a cookbook_file in an non cookbook_file resource

On Monday, July 23, 2012 at 8:15 AM, nate_chadwick@percussion.com wrote:

> Hi All,

>

> We have a deployment scenario where we are deploying a war to a Tomcat server, and if a developer or ops person is in the exploded war directory at the time, tomcat fails to redeploy the war file. We are not using the application cookbook.

>

> What I would like to do is add a file and directory resource to delete the war file and exploded war directory if the war file’s checksum has changed prior to the cookbook_file line. I am assuming that the cookbook_file resource always uses the checksum by default. Recipe snippet below:

>

> #Caching

> file “#{node[:tomcat][:webapp_dir]}/perc-caching.war” do

> action :delete

> only_if [checksum of new cookbook file doesn’t match installed cookbook file]

> end

>

> directory “#{node[:tomcat][:webapp_dir]}/perc-caching” do

> action :delete

> recursive true

> only_if [checksum of new cookbook file doesn’t match installed cookbook file]

> end

>

> cookbook_file “#{node[:tomcat][:webapp_dir]}/perc-caching.war” do

> source “perc-caching.war”

> backup false

> owner “#{node[:tomcat][:user]}”

> group “#{node[:tomcat][:group]}”

> only_if [is this implied by the cookbook_file resource?]

> end

>

> Is there a way to get the checksum of the cookbook_file that is currently installed and comparing it to the checksum of the new cookbook file so that the delete actions on the file and directory resources only run when the file has changed?

>

>

> Any help,tips, comments, appreciated.

>

> Thanks!

>

> Nate Chadwick • Percussion Software

> (O) 781-835-1356 | nate_chadwick@percussion.com (mailto:nate_chadwick@percussion.com)

You want to chain the resources together with notifications:

http://wiki.opscode.com/display/chef/Resources#Resources-Notifications

Then you probably also want to use action :nothing on the other resources.

Dan DeLeo