Skip to content

Instantly share code, notes, and snippets.

@chris-gilmore
Created March 29, 2011 08:42
Show Gist options
  • Save chris-gilmore/892017 to your computer and use it in GitHub Desktop.
Save chris-gilmore/892017 to your computer and use it in GitHub Desktop.
Bootstrap Chef Server
# references
# http://wiki.opscode.com/display/chef/Bootstrap+Chef+RubyGems+Installation
# http://wiki.opscode.com/display/chef/Launch+Cloud+Instances+with+Knife
$ cat <<EOF | sudo tee /etc/hosts
127.0.0.1 chef.example.com chef localhost
EOF
$ echo chef | sudo tee /etc/hostname
$ sudo apt-get -y update
$ sudo apt-get -y upgrade
$ sudo reboot
$ sudo apt-get -y install emacs ntp ruby ruby-dev libopenssl-ruby rdoc ri irb build-essential wget ssl-cert libreadline-ruby libruby libxslt-dev libxml2-dev
$ cd /tmp
$ wget http://production.cf.rubygems.org/rubygems/rubygems-1.6.2.tgz
$ tar zxf rubygems-1.6.2.tgz
$ cd rubygems-1.6.2
$ sudo ruby setup.rb --no-format-executable
$ sudo gem install chef --no-rdoc --no-ri
$ sudo mkdir /etc/chef
$ cat <<EOF | sudo tee /etc/chef/solo.rb
file_cache_path "/tmp/chef-solo"
cookbook_path "/tmp/chef-solo/cookbooks"
EOF
$ cat <<EOF > ~/chef.json
{
"chef": {
"server_url": "http://localhost:4000",
"webui_enabled": true
},
"run_list": [ "recipe[chef::bootstrap_server]" ]
}
EOF
$ sudo chef-solo -c /etc/chef/solo.rb -j ~/chef.json -r http://s3.amazonaws.com/chef-solo/bootstrap-latest.tar.gz | tee ~/bootstrap.log
# Open ports 4000 (api) and 4040 (webui) in the firewall for the chef server.
# Login to the chef server webui with the default admin credentials and then immediately change the default password.
# url: http://chef.example.com:4040
# username: admin
# password: p@ssw0rd1
$ mkdir ~/.chef
$ sudo cp /etc/chef/{validation,webui}.pem ~/.chef
$ sudo chown $USER:$USER ~/.chef/{validation,webui}.pem
$ cd ~
$ knife configure -i
No knife configuration file found
Where should I put the config file? [~/.chef/knife.rb]
Please enter the chef server URL: [http://localhost:4000]
Please enter a clientname for the new client: [ubuntu]
Please enter the existing admin clientname: [chef-webui]
Please enter the location of the existing admin client's private key: [/etc/chef/webui.pem] .chef/webui.pem
Please enter the validation clientname: [chef-validator]
Please enter the location of the validation key: [/etc/chef/validation.pem] .chef/validation.pem
Please enter the path to a chef repository (or leave blank):
WARN: Creating initial API user...
INFO: Created (or updated) client[ubuntu]
WARN: Configuration file written to /home/ubuntu/.chef/knife.rb
$ chmod 600 ~/.chef/{knife.rb,$USER.pem}
$ knife client list
$ sudo gem install net-ssh net-ssh-multi highline fog --no-rdoc --no-ri
$ cat <<EOF >> ~/.chef/knife.rb
# EC2
knife[:aws_access_key_id] = "Your AWS Access Key"
knife[:aws_secret_access_key] = "Your AWS Secret Access Key"
EOF
$ knife ec2 server list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment