Skip to content

Instantly share code, notes, and snippets.

@mriddle
Created November 9, 2012 00:11
Show Gist options
  • Save mriddle/4042808 to your computer and use it in GitHub Desktop.
Save mriddle/4042808 to your computer and use it in GitHub Desktop.
Creating and setting up a chef server
#cloud-config
output:
all: ">> /var/log/cloud-init.log"
# the chef server's alias will be "chef", add a /etc/hosts entry for it
bootcmd:
- echo 127.0.0.1 chef >> /etc/hosts
apt_sources:
- source: "deb http://apt.opscode.com/ precise-0.10 main"
key: |
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.9 (GNU/Linux)
mQGiBEppC7QRBADfsOkZU6KZK+YmKw4wev5mjKJEkVGlus+NxW8wItX5sGa6kdUu
twAyj7Yr92rF+ICFEP3gGU6+lGo0Nve7KxkN/1W7/m3G4zuk+ccIKmjp8KS3qn99
dxy64vcji9jIllVa+XXOGIp0G8GEaj7mbkixL/bMeGfdMlv8Gf2XPpp9vwCgn/GC
JKacfnw7MpLKUHOYSlb//JsEAJqao3ViNfav83jJKEkD8cf59Y8xKia5OpZqTK5W
ShVnNWS3U5IVQk10ZDH97Qn/YrK387H4CyhLE9mxPXs/ul18ioiaars/q2MEKU2I
XKfV21eMLO9LYd6Ny/Kqj8o5WQK2J6+NAhSwvthZcIEphcFignIuobP+B5wNFQpe
DbKfA/0WvN2OwFeWRcmmd3Hz7nHTpcnSF+4QX6yHRF/5BgxkG6IqBIACQbzPn6Hm
sMtm/SVf11izmDqSsQptCrOZILfLX/mE+YOl+CwWSHhl+YsFts1WOuh1EhQD26aO
Z84HuHV5HFRWjDLw9LriltBVQcXbpfSrRP5bdr7Wh8vhqJTPjrQnT3BzY29kZSBQ
YWNrYWdlcyA8cGFja2FnZXNAb3BzY29kZS5jb20+iGAEExECACAFAkppC7QCGwMG
CwkIBwMCBBUCCAMEFgIDAQIeAQIXgAAKCRApQKupg++Caj8sAKCOXmdG36gWji/K
+o+XtBfvdMnFYQCfTCEWxRy2BnzLoBBFCjDSK6sJqCu5Ag0ESmkLtBAIAIO2SwlR
lU5i6gTOp42RHWW7/pmW78CwUqJnYqnXROrt3h9F9xrsGkH0Fh1FRtsnncgzIhvh
DLQnRHnkXm0ws0jV0PF74ttoUT6BLAUsFi2SPP1zYNJ9H9fhhK/pjijtAcQwdgxu
wwNJ5xCEscBZCjhSRXm0d30bK1o49Cow8ZIbHtnXVP41c9QWOzX/LaGZsKQZnaMx
EzDk8dyyctR2f03vRSVyTFGgdpUcpbr9eTFVgikCa6ODEBv+0BnCH6yGTXwBid9g
w0o1e/2DviKUWCC+AlAUOubLmOIGFBuI4UR+rux9affbHcLIOTiKQXv79lW3P7W8
AAfniSQKfPWXrrcAAwUH/2XBqD4Uxhbs25HDUUiM/m6Gnlj6EsStg8n0nMggLhuN
QmPfoNByMPUqvA7sULyfr6xCYzbzRNxABHSpf85FzGQ29RF4xsA4vOOU8RDIYQ9X
Q8NqqR6pydprRFqWe47hsAN7BoYuhWqTtOLSBmnAnzTR5pURoqcquWYiiEavZixJ
3ZRAq/HMGioJEtMFrvsZjGXuzef7f0ytfR1zYeLVWnL9Bd32CueBlI7dhYwkFe+V
Ep5jWOCj02C1wHcwt+uIRDJV6TdtbIiBYAdOMPk15+VBdweBXwMuYXr76+A7VeDL
zIhi7tKFo6WiwjKZq0dzctsJJjtIfr4K4vbiD9Ojg1iISQQYEQIACQUCSmkLtAIb
DAAKCRApQKupg++CauISAJ9CxYPOKhOxalBnVTLeNUkAHGg2gACeIsbobtaD4ZHG
0GLl8EkfA8uhluM=
=zKAm
-----END PGP PUBLIC KEY BLOCK-----
debconf_selections: |
chef-server-webui chef-server-webui/admin_password password chef
chef-solr chef-solr/amqp_password password chef
chef chef/chef_server_url string http://chef:4000
runcmd:
- [ "apt-get", "update" ]
- [ "apt-get", "-y", "upgrade" ]
- [ "apt-get", "-y", "install", "chef" ]
- [ "apt-get", "-y", "install", "chef-server" ]
packages:
- git-core

Resources:

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment