Skip to content

Instantly share code, notes, and snippets.

@jtimberman
Created May 3, 2012 18:06
Show Gist options
  • Save jtimberman/2587738 to your computer and use it in GitHub Desktop.
Save jtimberman/2587738 to your computer and use it in GitHub Desktop.
Check the cookbooks are frozen and specified in non development environments
if node.chef_environment != 'development'
cookbooks = {}
node.cookbook_collection.values.each {|c| cookbooks[c.name.to_s] = c.version.to_s }
# See https://github.com/danryan/spice
r = gem_package "spice" do
version "0.8.0"
end
r.run_action(:install)
require 'rubygems'
Gem.clear_paths
require 'spice'
Spice.server_url = Chef::Config.chef_server_url
Spice.client_name = Chef::Config.node_name
Spice.key_file = Chef::Config.client_key
Spice.chef_version = "0.10.8"
Spice.connect!
require 'uri'
errors = ""
cookbooks.each_pair do |cookbook_name, version|
Chef::Log.debug("Checking cookbook '#{cookbook_name}:#{version}'")
if version.nil?
errors << "Cookbook '#{cookbook_name}' has no version specified.\n"
next
end
cookbook_url = nil
Spice::Cookbook[cookbook_name][cookbook_name]["versions"].each do |version_data|
if version_data["version"] == version
cookbook_url = URI(version_data["url"])
break
end
end
if cookbook_url.nil?
errors << "Unable to locate cookbook '#{cookbook_name}' version '#{version}'\n"
next
end
if !Spice.connection.get(cookbook_url.path)["frozen?"]
errors << "Cookbook '#{cookbook_name}' version '#{version}' is not frozen\n"
next
end
end
if errors.length > 0
Chef::Log.info(errors)
raise errors
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment