Skip to content

Instantly share code, notes, and snippets.

@jeremyd
Created July 8, 2011 05:34
Show Gist options
  • Save jeremyd/1071209 to your computer and use it in GitHub Desktop.
Save jeremyd/1071209 to your computer and use it in GitHub Desktop.
chef server bootstrap
#!/usr/bin/env ruby
puts `gem sources -a http://gems.opscode.com/`
puts `gem install chef`
solorb = <<EOF
file_cache_path "/tmp/chef-solo"
cookbook_path "/tmp/chef-solo/cookbooks"
recipe_url "http://s3.amazonaws.com/chef-solo/bootstrap-latest.tar.gz"
EOF
bootstrap = <<BOOT
{
"bootstrap": {
"chef": {
"url_type": "http",
"init_style": "runit",
"path": "/srv/chef",
"serve_path": "/srv/chef",
"server_fqdn": "#{ENV['EC2_PUBLIC_HOSTNAME']}",
"webui_enabled": true
}
},
"run_list": [ "recipe[bootstrap::server]" ]
}
BOOT
so="/root/solo.rb"
run="/root/chef.json"
File.open(so, "w") {|f| f.write(solorb)}
File.open(run, "w") {|f| f.write(bootstrap)}
orig_hosts = IO.read("/etc/hosts")
orig_hosts.gsub!(/127\.0\.0\.1 /, "127.0.0.1 #{ENV['EC2_PUBLIC_HOSTNAME']} ")
File.open("/etc/hosts", "w") {|f| f.write(orig_hosts)}
puts `chef-solo -c #{so} -j #{run}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment