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:
C:\chef
C:\devkit
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:
cd ~
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:
OpscodeOrganizationName-validator
Now you really are ready to start cooking with chef using a windows 7 admin machine J
HI, Thanks for this. I have gotten this far on my windows client. What I am having issues with, is when I run the chef-client command against my client.rb config, I get this error :
:29:in `require’: C:/Users/hylandm.MXITZA/Documents/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/ruby-wmi-0.2.2/lib/ruby-wmi/base.rb:52: syntax error, unexpected ‘:’, expecting keyword_then or ‘,’ or ‘;’ or ‘\n’ (SyntaxError)
when /Invalid class/i : raise InvalidClass
^
C:/Users/hylandm.MXITZA/Documents/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/ruby-wmi-0.2.2/lib/ruby-wmi/base.rb:53: syntax error, unexpected keyword_when, expecting keyword_end
when /Invalid query/i : raise InvalidQuery
^
C:/Users/hylandm.MXITZA/Documents/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/ruby-wmi-0.2.2/lib/ruby-wmi/base.rb:53: syntax error, unexpected ‘:’, expecting keyword_end
when /Invalid query/i : raise InvalidQuery
^
C:/Users/hylandm.MXITZA/Documents/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/ruby-wmi-0.2.2/lib/ruby-wmi/base.rb:180: syntax error, unexpected keyword_end, expecting $end
from :29:in `require’
from C:/Users/hylandm.MXITZA/Documents/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/ruby-wmi-0.2.2/lib/ruby-wmi.rb:10:in `’
from :33:in `require’
from :33:in `rescue in require’
from :29:in `require’
from C:/Users/hylandm.MXITZA/Documents/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/chef-0.10.0/lib/chef/provider/env/windows.rb:20:in `’
from :29:in `require’
from :29:in `require’
from C:/Users/hylandm.MXITZA/Documents/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/chef-0.10.0/lib/chef/providers.rb:49:in `’
from :29:in `require’
from :29:in `require’
from C:/Users/hylandm.MXITZA/Documents/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/chef-0.10.0/lib/chef.rb:25:in `’
from :29:in `require’
from :29:in `require’
from C:/Users/hylandm.MXITZA/Documents/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/chef-0.10.0/bin/chef-client:23:in `’
from C:/Users/hylandm.MXITZA/Documents/Ruby1.9.2/bin/chef-client:19:in `load’
from C:/Users/hylandm.MXITZA/Documents/Ruby1.9.2/bin/chef-client:19:in `’
This only tends to happen with Ruby V1.9.2 – 1.9.8 seems to work fine
Any feed back would be much appreciated.
Thanks,
Mike
Sorry meant ruby 1.8.7
Hi Mike,
Ruby,chef & windows does seem to suffer from “versionitis” so if you don’t get all the pre-req gems installed properly you could find yourself chasing your tail . If the only reason you are using ruby is to run chef then it should still work if you use ruby 1.8.7. I’m not clear though if the issue is on your target node and if so what version of windows is it?
I would also post your error on the opscode site so we have more than just me trying to help .
Grace
Hi Grace,
Thanks for reply – I have re-installed Ruby 1.8.7 and am having a measure of success. Thanks fro the feedback.
Mike
Hi Grace – I might have submitted this post twice – not sure if there is a moderation period, but I did not see my first post appear. So if I have posted twice, my aplogies.
I am having an interesting issue that I have submitted to opscode but thought you might have some answers. I have configured a Chef server on Centos 5.4 and created two clients – one on Windows 2008 server and Windows 7 respectively. The issue that I am having is that a chef-client run authenticates on my Win 7 box but not on the Win 2008 box. Both clients have been created using the knife client create command on the server and copied the .pem files to the clients.
Here are my configs and results :
Win 2008 knife and client configs :
KNIFE.RB :
log_level :info
log_location STDOUT
node_name ‘frqamsbot02′
client_key ‘F:/Services/Admin/chef-repo/.chef/frqamsbot02.pem’
validation_client_name ‘chef-validator’
validation_key ‘F:/Services/Admin/chef-repo/.chef/frqamsbot02.pem’
chef_server_url ‘http://chef.mxit.com:4000′
cache_type ‘BasicFile’
cache_options( :path => ‘F:/Services/Admin/chef-repo/.chef/checksums’ )
CLIENT.RB :
log_level :info
log_location STDOUT
node_name “frqamsbot02″
client_key “F:/Services/Admin/chef-repo/.chef/frqamsbot02.pem”
validation_client_name “frqamsbot02″
validation_key “F:/Services/Admin/chef-repo/.chef/frqamsbot02.pem”
chef_server_url “http://chef.mxit.com:4000″
cache_type ‘BasicFile’
cache_options( :path => “F:/Services/Admin/chef-repo/.chef/.chef/checksums” )
cookbook_path ["f:/services/admin/chef-repo/cookbooks"]
knife client list result :
F:\Services\Admin\chef-repo>knife client list
chef-validator
chef-webui
frqamsbot02
root
chef-client result :
F:\Services\Admin\chef-repo\.chef>chef-client -c client.rb
[Wed, 11 May 2011 14:21:50 +0200] INFO: *** Chef 0.10.0 ***
[Wed, 11 May 2011 14:22:03 +0200] INFO: HTTP Request Returned 404 Not Found: Cannot load node frqamsbot02
[Wed, 11 May 2011 14:22:07 +0200] INFO: Run List is []
[Wed, 11 May 2011 14:22:07 +0200] INFO: Run List expands to []
[Wed, 11 May 2011 14:22:07 +0200] INFO: Starting Chef Run for frqamsbot02
[Wed, 11 May 2011 14:22:08 +0200] INFO: Loading cookbooks []
[Wed, 11 May 2011 14:22:08 +0200] WARN: Node frqamsbot02 has an empty run list.
[Wed, 11 May 2011 14:22:17 +0200] INFO: HTTP Request Returned 401 Unauthorized: Failed to authenticate. Ensure that your client key is valid.
[Wed, 11 May 2011 14:22:17 +0200] ERROR: Running exception handlers
[Wed, 11 May 2011 14:22:17 +0200] FATAL: Saving node information to F:/var/chef/cache/failed-run-data.json
[Wed, 11 May 2011 14:22:17 +0200] ERROR: Exception handlers complete
[Wed, 11 May 2011 14:22:17 +0200] FATAL: Stacktrace dumped to F:/var/chef/cache/chef-stacktrace.out
[Wed, 11 May 2011 14:22:17 +0200] FATAL: Net::HTTPServerException: 401 “Unauthorized”
Here is my Win 7 configs :
KNIFE.RB :
log_level :info
log_location STDOUT
node_name ‘mike-laptop’
client_key ‘C:/Users/hylandm.MXITZA/.chef/mike-laptop.pem’
validation_client_name ‘mike_laptop’
validation_key ‘c:/users/hylandm.MXITZA/.chef/mike-laptop.pem’
chef_server_url ‘http://chef.mxit.com:4000′
cache_type ‘BasicFile’
cache_options( :path => ‘C:/Users/hylandm.MXITZA/.chef/checksums’ )
cookbook_path ‘c:/users/hylandm.MXITZA/chef/chef-repo/cookbook
CLIENT.RB :
log_level :info
log_location STDOUT
node_name “mike-laptop”
client_key “c:/users/hylandm.MXITZA/.chef/mike-laptop.pem”
validation_client_name “mike_laptop”
validation_key “c:/users/hylandm.MXITZA/.chef/mike-laptop.pem”
chef_server_url “http://chef.mxit.com:4000″
cache_type ‘BasicFile’
cache_options( :path => ‘c:/users/hylandm.MXITZA/chef/.chef/checksums’ )
cookbook_path ["c:/users/hylandm.MXITZA/documents/chef/chef-repo/cookbooks"]
knife client list result :
C:\Users\hylandm.MXITZA>knife client list
chef-validator
chef-webui
frqamsbot02
mike-laptop
root
chef-client result :
C:\Users\hylandm.MXITZA\.chef>chef-client -c client.rb
[Wed, 11 May 2011 14:27:21 +0200] INFO: *** Chef 0.10.0 ***
[Wed, 11 May 2011 14:28:12 +0200] INFO: HTTP Request Returned 404 Not Found: Cannot load node mike-laptop
[Wed, 11 May 2011 14:28:12 +0200] INFO: Run List is []
[Wed, 11 May 2011 14:28:12 +0200] INFO: Run List expands to []
[Wed, 11 May 2011 14:28:12 +0200] INFO: Starting Chef Run for mike-laptop
[Wed, 11 May 2011 14:28:13 +0200] INFO: Loading cookbooks []
[Wed, 11 May 2011 14:28:13 +0200] WARN: Node mike-laptop has an empty run list.
[Wed, 11 May 2011 14:28:18 +0200] INFO: Chef Run complete in 5.39754 seconds
[Wed, 11 May 2011 14:28:18 +0200] INFO: Running report handlers
[Wed, 11 May 2011 14:28:18 +0200] INFO: Report handlers complete
So as you can see the chef-client run on the Win 7 laptop is succcesfull but not on the Win2008 server. I have no idea where I am going wrong.
Your help is much appreciated.
Thanks,
Mike
Hi, your post got caught by the spam filter hence why I didn’t see it earlier . I can’t spot anything obvious have you run chef-client with the -l flag? I guess the guys at opscode have asked you to do this too.
Windows 2008 is ‘more ‘ sensitive so it may be the fact a gem needs pre-loading prior to running knife against it? I had an issue with authentication on windows 2008 ( I’m targeting w 2008 r2 now) in an older version of chef but that got fixed
Hi Grace,
“so it may be the fact a gem needs pre-loading prior to running knife against it?”
Could you explain this a bit more. Can you confirm that you have got this working on a Win 2008 R2 machine?
I am about to try on one now.
Thanks.
haha!! Ok so it seems like it works happily on an R2 machine.
Wow – what a mission.
Thanks for you help Grace.
Mike
Hi Mike,
Not sure I was that helpful it maybe just the bouncing around thing
Problem the Opscode guys have is there isn’t the traction of windows users so its people like you & me helping them out as after the pain the rewards are worth it.
Yeah – I agree. In our environment we have loads of windows and Linux boxes and at the moment I would like to get the automation of msi deployments on our windows machines running smoothly. I have conteacted the opscode team and let them know about how I resolved my issue and told them that it would be handy to let people know that 2008 standard machines do have some sort of authentication issues.
I followed the directions above and am getting the same error that Mike posted back in May. I tried using both 1.8.7 and 1.9.2 versions of ruby, without success. I want to setup my Windows 7 Enterprise SP1, 64bit machine as a chef management station. I have the following installed:
Ruby 1.9.2-p290
DevKit-4.5.2-20110712-1620
*** LOCAL GEMS ***
bunny (0.7.4)
chef (0.10.4)
erubis (2.7.0)
highline (1.6.2)
hoe (2.12.0)
json (1.5.2)
mime-types (1.16)
minitest (1.6.0)
mixlib-authentication (1.1.4)
mixlib-cli (1.2.0)
mixlib-config (1.1.2)
mixlib-log (1.3.0)
moneta (0.6.0)
net-ssh (2.1.4)
net-ssh-gateway (1.1.0)
net-ssh-multi (1.1)
ohai (0.6.4)
polyglot (0.3.2)
rake (0.8.7)
rdoc (2.5.8)
rest-client (1.6.3)
ruby-wmi (0.2.2)
systemu (2.2.0)
treetop (1.4.10)
uuidtools (2.1.2)
win32-api (1.4.8 x86-mingw32)
windows-api (0.4.0)
windows-pr (1.2.0)
yajl-ruby (0.8.2)
The installation goes smoothly, and I don’t get any errors. Then I try to run “chef-client -v” and get the following errors:
C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require’:
C:/Ruby192/lib/ruby/gems/1.9.1/gems/ruby-wmi-0.2.2/lib/ruby-wmi/base.rb:52: synt
ax error, unexpected ‘:’, expecting keyword_then or ‘,’ or ‘;’ or ‘\n’ (SyntaxEr
ror)
when /Invalid class/i : raise InvalidClass
^
C:/Ruby192/lib/ruby/gems/1.9.1/gems/ruby-wmi-0.2.2/lib/ruby-wmi/base.rb:53: synt
ax error, unexpected keyword_when, expecting keyword_end
when /Invalid query/i : raise InvalidQuery
^
C:/Ruby192/lib/ruby/gems/1.9.1/gems/ruby-wmi-0.2.2/lib/ruby-wmi/base.rb:53: synt
ax error, unexpected ‘:’, expecting keyword_end
when /Invalid query/i : raise InvalidQuery
^
C:/Ruby192/lib/ruby/gems/1.9.1/gems/ruby-wmi-0.2.2/lib/ruby-wmi/base.rb:180: syn
tax error, unexpected keyword_end, expecting $end
from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:i
n `require’
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/ruby-wmi-0.2.2/lib/ruby-wmi.rb:
10:in `’
from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:57:i
n `require’
from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:57:i
n `rescue in require’
from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:i
n `require’
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/chef-0.10.4/lib/chef/provider/e
nv/windows.rb:20:in `’
from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:i
n `require’
from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:i
n `require’
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/chef-0.10.4/lib/chef/providers.
rb:49:in `’
from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:i
n `require’
from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:i
n `require’
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/chef-0.10.4/lib/chef.rb:25:in `
‘
from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:i
n `require’
from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:i
n `require’
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/chef-0.10.4/bin/chef-client:23:
in `’
from C:/Ruby192/bin/chef-client:19:in `load’
from C:/Ruby192/bin/chef-client:19:in `’
Any ideas? Thanks.
Hi,
Try testing using the knife command as this is what you will be using for management if that still give errors then it will mean a bit more digging around to try and work out what is happening.
Grace
Hi,
I had the same problem. Knife command was working. But as I needed to use this computer also as client, I dug around.
The problem is in ruby-wmi/base.rb, replace ‘:’ with ‘;’ (lines 52 and 53) see bug report and my post about chef install on windows.
This is no longer a problem refer to my post on the Chef windows MSI http://devopscloud.net/2012/01/15/one-tool-to-manage-them-all/ . The pain has gone