Resources:
- https://github.com/fnichol/wiki-notes/wiki/Deploying-Chef-Server-On-Amazon-EC2
- http://wiki.opscode.com/display/chef/Installing+Chef+Server+using+Chef+Solo
- http://www.ducea.com/2009/06/01/howto-update-dns-hostnames-automatically-for-your-amazon-ec2-instances/
- http://wiki.opscode.com/display/chef/Installing+Chef+Server+Manually#InstallingChefServerManually-ConfiguretheCommandLineClient
Setup your box
- Add AWS Access Key ID and Secret to environment variables (AWS_ACCESS_ID & AWS_SECRET_KEY)
- Install ec2-api-tools or
brew install ec2-api-tools
- You should have the cloud-init file in your repo
- You should have knife installed (gem install knife-ec2)
Create a new Chef server
cd ~/projects/your-chef-repo ec2-run-instances --instance-type m1.small ami-a29943cb --subnet subnet-a6371fcd --availability-zone us-east-1c --user-data-file chef_server.init -g sg-95759bfa -k sppdev > new_chef_instance_output.txt cat new_chef_instance_output.txt ec2-create-tags `cat new_chef_instance_output.txt | grep '^INSTANCE' | cut -f2 -s` --tag "Name=Chef-Server" #ssh into new instance and tail /var/log/cloud-init.log /var/log/chef/server.log #Wait for the box to finish setting up #Ensure chef-server and chef-server-webui have started. ssh ubuntu@your-chef-server sudo service chef-server status sudo service chef-server-webui status #I had to run webui via 'sudo chef-server-webui' first before I could start the service successfully
Configure knife run the following on the new chef server
mkdir -p ~/.chef sudo cp /etc/chef/validation.pem /etc/chef/webui.pem ~/.chef sudo chown -R $USER ~/.chef knife configure -i #Where should I put the config file? [~/.chef/knife.rb] #Please enter the chef server URL: [http://server_name:4000] http://localhost:4000 #Please enter a clientname for the new client: [ubuntu] dev #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): #Creating initial API user... #Created client[dev] #Configuration file written to /home/ubuntu/.chef/knife.rb #Copy the contents of the pem into your chef-repo (.chef/dev-client.pem) cat .chef/dev.pem
Test your Chef server and Knife configuration From your local dev machine
cd ~/projects/lpos-chef-repo knife client list
Update chef server password Go to http://your-chef-server.com:4040/users/admin/update and update the password to something else
Upload our cookbooks to chef server From your local dev machine
knife cookbook upload -a knife role from file roles/*.json
Notes:
Handy tips on troubleshooting can be found here
Breakdown of ec2-run-instances command ec2-run-instances --instance-type m1.small ami-a29943cb --subnet subnet-a6371fcd --availability-zone us-east-1c --user-data-file chef_server.init -g sg-95759bfa -k sppdev
- --instance-type m1.small ami-a29943cb
- Instance Type and vanilla ubuntu AMI.
- --subnet subnet-a6371fcd --availability-zone us-east-1c
- Only required if your launching within a VPC
- --user-data-file chef_server.init
- The cloud init file used. Baked into ubuntu AMIs
- -g sg-95759bfa The ID of the VPC security group.
- If not launching an instance within a VPC you can reference the group by name
- -k sppdev
- The key to use. sppdev is the name for the access key/secret pair setup in security credentials