Created
November 10, 2011 07:49
-
-
Save Atalanta/1354377 to your computer and use it in GitHub Desktop.
Retrieve all README files from Chef Server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def cookbook_urls | |
cookbooks = api.get("/cookbooks") | |
cookbooks.keys.map do |cb| | |
cookbooks[cb]['versions'].last['url'] | |
end | |
end | |
def fetch_readme_url(cookbook_version_path) | |
print "." | |
cb_hash = api.get("/#{cookbook_version_path}").to_hash | |
results = cb_hash['root_files'].select { |f| f['name'] == 'README.md' } | |
if results.empty? | |
nil | |
else | |
results.first['url'] | |
end | |
end | |
def readmes | |
readme_urls = cookbook_urls.map do |cookbook_url| | |
path = cookbook_url.split('/')[-3, 3].join('/') | |
{ | |
:name => path.split('/')[1], | |
:url => fetch_readme_url(path) | |
} | |
end | |
puts "\n===> Preparing to download READMEs." | |
readme_urls.reject! { |h| h[:url].nil? } | |
end | |
puts "===> Fetching metadata from Chef Server..." | |
readmes.each do |readme| | |
puts "===> Fetching #{readme[:name]} ..." | |
%x[curl -s -o README-#{readme[:name]}.md '#{readme[:url]}'] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ knife exec get_readmes.rb | |
===> Fetching metadata from Chef Server... | |
................ | |
===> Preparing to download READMEs. | |
===> Fetching ips ... | |
===> Fetching solaris ... | |
===> Fetching sudo ... | |
===> Fetching application ... | |
===> Fetching git ... | |
===> Fetching users ... | |
===> Fetching rvm ... | |
$ ls -l *md | |
total 6 | |
-rw-rw-r-- 1 atalanta atalanta 234 Nov 10 07:41 README-application.md | |
-rw-rw-r-- 1 atalanta atalanta 2483 Nov 10 07:41 README-git.md | |
-rw-rw-r-- 1 atalanta atalanta 1338 Nov 10 07:41 README-ips.md | |
-rw-rw-r-- 1 atalanta atalanta 31863 Nov 10 07:41 README-rvm.md | |
-rw-rw-r-- 1 atalanta atalanta 1075 Nov 10 07:41 README-solaris.md | |
-rw-rw-r-- 1 atalanta atalanta 2616 Nov 10 07:41 README-sudo.md | |
-rw-rw-r-- 1 atalanta atalanta 3426 Nov 10 07:41 README-users.md |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment