Managing Chef from Windows 7
April 17, 2011 14 Comments
Opscode have made significant progress in allowing windows users to use their windows machines to administer chef as it is using a Linux workstation. This is great news for all us chef lovers who use windows as their main day to day environment and if like me you have to target both Linux and windows nodes.
In the past I have had problems using previous versions of chef with ruby version 1.8.7-x which would require me having to explicitly tell knife where to find config files, installing extra gems just to get it to work and I was always reluctant to not have handy a Linux instance available as a fall back .
This post summarises the steps required to set up your windows environment to use version 0.10.0 of Chef on the Opscode Platform with ruby 1.9.2 p-180 . Hopefully this will save you hopping all over the place to find out what you need to do to get it sorted out.
This version of Chef provides the ability to have different environments hence why I opted to start playing with the beta/ pre-release version.
Environments are a welcome addition as it means you can easily manage test, stage and production environments with the use of different run lists per environment for the same role . For example the only thing likely to differ between say stage and production is likely to be target databases, S3 buckets, account names etc so you could add in specific attribute files for these values per environment.
Firstly sign up with the opscode platform via opscode.com downloading the knife configuration and the private keys that are generated. I’m not going through that as the guys at Opscode have done a great job of walking you through that process.
1. Install ruby
· Download from http://rubyinstaller.org the latest version of ruby ( at time of writing this was ruby 1.9.2 p-180)
(There is a vbs script that allows you to do a wget from the opscode wiki site but why would you do this ? I’m not sure, but if you do feel the need to script this bit what’s wrong with Powershell?)
· Run the installer
2. Create the following folders:
3. Install the Ruby Devkit
· Download from https://github.com/oneclick/rubyinstaller/wiki/Development-Kit the ruby development kit
· Extract the devkit into c:\devkit by copying the downloaded devkit.exe into c:\devkit, then extracting it using DevKit-tdm-32-4.5.1-20101214-1400-sfx.exe –y
Then run the following
· ruby c:/DevKit/dk.rb init
· ruby c:/DevKit/dk.rb install
4. Install some gems that are pre-requisites : gem install ruby-wmi windows-api windows-pr
5. Install version 0.10.0 of chef. As I have been using the beta / pre-release version my installation command looked like this : gem install chef –pre –no-rdoc –no-ri –verbose
When the stable release of version 0.10.0 is available the command will be:
gem install chef –no-rdoc –no-ri –verbose
6. Install git for windows from http://help.github.com/win-set-up-git/ This is needed as Chef makes use of github as a repository and you will need this to at least set up your initial environment and to download sample cookbooks. It’s also a good choice of a repository to keep your own cookbooks if you do not already have a repository.
7. Create a chef repository. This is where the artefacts that you will use to manage your target nodes are located. These include cookbooks, roles etc. To do this clone a copy from git. Assuming your working environment is all under users/yourname and you are using Git bash:
git clone git://github.com/opscode/chef-repo.git
8. Create a .chef folder under your chef-repo folder
9. Copy the knife.rb and keys into the .chef folder. Now whenever you are in the chef-repo folder and run a knife command it will locate both these files.
10. If you are using AWS ec2 resources like I am then you will also need to install the ec2 commands plugin
gem install knife-ec2 –no-rdoc –no-ri –verbose
Two extra lines will then need to be added to the knife.rb file copied to ~/chef-repo/.chef earlier to allow you to use the knife ec2 commands
knife[:aws_access_key_id] = “YOUR_ACCESS_KEY_ID_HERE”
knife[:aws_secret_access_key] = “YOUR_SECRET_ACCESS_KEY”
11. As a quick verification run the following command from your chef-repo folder:
Knife client list
This should return the default client set up when you first sign up:
Now you really are ready to start cooking with chef using a windows 7 admin machine J