Skip to content

Instantly share code, notes, and snippets.

@gmcmillan
Created February 13, 2013 01:21
Show Gist options
  • Save gmcmillan/4802975 to your computer and use it in GitHub Desktop.
Save gmcmillan/4802975 to your computer and use it in GitHub Desktop.
Quick ruby script to download all cookbooks (all versions) from a Chef server.
#!/usr/bin/env ruby
cookbook_list = `knife cookbook list -a`.split("\n")
cookbook_list.each do |line|
line.strip!
line.match(/^([a-z0-9]+\-[a-z0-9-]+|\w+)\s+(\d\.\d\.\d|.+)$/)
name = $1
versions = $2
versions_array = versions.split(" ")
versions_array.each do |version|
if File.directory?("cookbooks_archived/#{name}-#{version}")
puts "Skipping #{name}, version #{version}. Cookbook exists."
else
puts "Downloading #{name}, version #{version}"
`knife cookbook download #{name} #{version} -d cookbooks_archived`
end
end
end
@raghureddy45
Copy link

raghureddy45 commented Aug 22, 2018

If cookbook has - instead of _ its not matching
for ex: testing_ca-certs. may be need to update regex?

@kumarincloud
Copy link

kumarincloud commented Oct 16, 2018

getting error, can u pls help here
cookbook.rb:12:in block in <main>': undefined method split' for nil:NilClass (NoMethodError)
from cookbook.rb:6:in each' from cookbook.rb:6:in

'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment