Recently I had chance to evaluate usage of Chef for deployment of web service on project I am working on.
There are plenty of resources available and this post is meant mostly as a serie of personal notes based on my current experience so I can easily return to it.
Chef client can run in two modes:
Standalone called chef solo
- Uses chef-solo command without attempts to access the server
- Works greatly for development of cookbooks or just for simple setup of the environment.
- Allows to define environment in JSON config file.
- Node specific information has to be defined
- Requires installed chef server.
- Allows to bootstrap newly provisioned machine very easily.
- Per-node setup can be maintained on the server.
- Chef server has to be installed on a Linux machine, there is no installation for Windows.
- Setup is pretty straightforward and well documented and I was able to perform it even with my outdated Linux knowledge.
- The WebUI is paid feature but for me as a developer the command line turned out to be much better understandable.
Although it allows to save files as a part of cookbook it seems to be pretty bad idea. Better is to have deployment packages available on some artifact server.
Creating first cookbook
- For development the Chef development kit can be installed:
- For initial playing with cookbook the client seems to be sufficient but development kit has some advanced features like static analysis, testing support etc. More to come…
- knife command helps here quite a bit although manual setup is obviously possible.
- It is best to maintain cookbook repository in GIT.
- For example dependency installation command is integrated with git.
- In git repository which will contain cookbook run:
knife cookbook create COOKBOOK_NAME
- Review created files to add documentation as needed.
- To install any dependencies run:
- This by default works with master branch. See other parameters to make it working on current branch.
- Dependency can be installed/managed manually as well if git is not available.
knife cookbook site install COOKBOOK_NAME
- Define dependencies in metadata.rb file
- Each dependency can contain version information to maintain compatibility.