Hosting your own Chef
Chef seems to be a pretty decent tool but it took me a while to get a working server & client set up on version 12 due to the merging of the old Enterprise and Open Source editions that were available in version 11, the subtle differences between the two, and the lack of documentation currently available for version 12.
Here’s how I managed to get it set up and working.
Environment
Server
- OS: ubuntu-14.04.1-server
- Hostname: chefserver
- Chef: chef-server-core_12.0.0-rc.3-1
- HDD: 40 GB
Workstation
- OS: ubuntu-14.04.1-server
- Hostname: chefwork
- Chef: chefdk-0.2.1-1
- HDD: 20 GB
Variables
Wherever you see a value in < > below (e.g. <username>
) replace it your own information.
Server
- Log in to your fresh server VM
- Download the server package
- Become root:
sudo -s
- Install the package:
dpkg -i chef-server*.deb
- Run the initial configuration:
chef-server-ctl reconfigure
-
Create your organisation and save the certificate to a file:
chef-server-ctl org-create <organisation> "<Long name in quotes>" -f <organisation>-validator.pem
-
Create your user and save the certificate to a file:
chef-server-ctl user-create <username> <FirstName> <LastName> <email> <password> -f <username>.pem
-
Associate your new user with your new organisation:
chef-server-ctl org-associate <organisation> <username>
Your server should now be set up, running, and have a user that can start adding nodes, etc.
As we used sudo your .pem
files are owned by root, so you might want to tidy those up:
chown <username>:<username> <username>.pem <organisation>-validator.pem
Workstation
- Log in to your fresh workstation VM
- Download the development kit
- Install the package:
sudo dpkg -i chefdk*.deb
- Create a folder for all your chef files:
chef generate repo chef-repo
-
Create the folder for certificates and config data:
cd chef-repo mkdir .chef cd .chef
-
Copy your certificates from the server to your new folder:
scp chefserver:~/*.pem . chmod go-rwx *.pem
- If you’re adding your
chef-repo
to source control remember to add an ignore rule for.chef/*.pem
(e.g.echo '.chef/*.pem' >> ~/chef-repo/.gitignore
for git) - With your favourite text editor, create a file called
knife.rb
inside your .chef folder with the following (not forgetting to replace<organisation>
). This assumes your chef<username>
matches your workstation username, if not, change thechef_user = `whoami`.chomp
line below tochef_user = '<username>'
Test your install by listing the users and nodes on your new server:
cd ..
knife user list
knife node list
The user list should show your <username>
, and the node list should
currently be blank, but neither should error.
That’s it! Your server and workstation are now configured and you can carry on with the tutorials.