I’ve been doing a lot of work with chef lately and the default workflow really sucks. Typically what I will do is make a change, commit it, then push it up to github. Then I will login to my chef server and run rake install in /var/chef-repo to pull from github and upload all the new cookbooks and roles into the running chef instance. Then I will login to the target server and run chef-client to see if my changes actually worked. This is more or less how it’s described in the wiki, which is why I call it the default workflow.
There are quite a few unnecessary steps there. It would be pretty rad if I could just type git push production on my laptop and then have the chef server pick up all the changes and then automatically have all the hosts in my cluster run chef-client. I don’t quite have it automated to that level yet. However, I was able to make it so that a git push production will trigger an upload of all my changes into the chef server. Here’s how it works.
This is all assuming that you are using Ubuntu Karmic server, by the way. If you are on another platform you may or may not be shit out of luck.
Setup the appropriate ACL’s for your chef repo. This is necessary if you are working in a team environment and wish to allow other people to push chef cookbooks to production.
sudo apt-get install acl
sudo mount -o remount,acl /dev/sda1
Change the fstab entry for the disk containing your chef repo to include the acl option.
/dev/sda1 / ext3 acl,defaults,errors=remount-ro,noatime 0 1
Create a group for the users who will be using this shared repo.
sudo groupadd chefadmin
sudo usermod cliff -G chefadmin
Then fix the permissions on your chef repo.
sudo chown -R root:chefadmin /var/chef-repo
sudo chmod -R g+w /var/chef-repo
sudo setfacl -R -m g:chefadmin:rwX /var/chef-repo
find /var/chef-repo -type d | xargs sudo setfacl -R -m d:g:chefadmin:rwX
Now you need to add a post-receive hook to your chef repo. Put the following in /var/chef-repo/.git/post-receive
#!/bin/sh
cd ..
env -i git reset --hard
rake roles upload_cookbooks
This hook will get run after a successful push to the repo. It will update the working tree by doing a hard reset and then run the rake tasks to upload everything to chef server.
And the last step is to simply add the git repo on your chef server as a remote.
git remote add production git+ssh://chef.mydomain.com/var/chef-repo/.git
Now git push production will automatically upload to your chef server and it will be usable by everyone in the chefadmin group as well.




