Tampa
Tampa

Reputation: 78234

Chef client keeps reinstalling recipe

I am fresh meat with chef. I am using chef to manage an ec2 instance ans seems to be working. When I log into the box I run the following so I can see what is happing.

sudo chef-client -i 60

I notice that my install for pytimer keeps getting reinstalled. How do I modify the recipe to ensure it only gets installed once unless there is a change to the recipe?

[Thu, 29 Mar 2012 00:28:01 +0000] INFO: Processing easy_install_package[hash_ring] action install (nginx_base::default line 107)
[Thu, 29 Mar 2012 00:28:02 +0000] INFO: Processing bash[compile_proto_source_source] action run (PyTimer::default line 8)
[Thu, 29 Mar 2012 00:28:02 +0000] INFO: bash[compile_proto_source_source] sh("bash"  "/tmp/chef-script20120329-23998-1te88gz-0")
timeout-0.1.2/
timeout-0.1.2/PKG-INFO
timeout-0.1.2/setup.py
timeout-0.1.2/timeout.py
running install
running build
running build_py
copying timeout.py -> build/lib.linux-x86_64-2.7
running install_lib
copying build/lib.linux-x86_64-2.7/timeout.py -> /usr/local/lib/python2.7/dist-packages
byte-compiling /usr/local/lib/python2.7/dist-packages/timeout.py to timeout.pyc
running install_egg_info
Removing /usr/local/lib/python2.7/dist-packages/timeout-0.1.2.egg-info
Writing /usr/local/lib/python2.7/dist-packages/timeout-0.1.2.egg-info




version = node[:PyTimer][:version]

remote_file "#{Chef::Config[:file_cache_path]}/timeout-#{version}.tar.gz" do
  source "http://pypi.python.org/packages/source/t/timeout/timeout-#{version}.tar.gz"
  #action :create_if_missing
end

bash "compile_proto_source_source" do
  cwd Chef::Config[:file_cache_path]
  code <<-EOH
    tar -xvf timeout-#{version}.tar.gz
    cd timeout-#{version}
    sed 's/signal.alarm(self.timeout)/signal.setitimer(signal.ITIMER_REAL,self.timeout)/g' -i timeout.py
  python setup install
  EOH
end

Upvotes: 2

Views: 801

Answers (1)

Charles Duffy
Charles Duffy

Reputation: 295281

Use an only_if or not_if condition (which can be either shell scripts or arbitrary blocks of ruby code) to identify the case where the work done by the script has already been accomplished. You can also have your script create a file on successful execution and use the creates argument to exec to run only when that file is not present.

All of these covered in the documentation for the exec resource.

Upvotes: 2

Related Questions