Saturday, March 24, 2012

Chef on Windows

http://www.opscode.com/blog/2011/05/24/chef-hearts-windows/

gem install knife-windows

Fetching: eventmachine-1.0.0.beta.3-java.gem (100%)
Fetching: gssapi-1.0.3.gem (100%)
ERROR:  Error installing knife-windows:
        gssapi requires Ruby version >= 1.9.1.

ruby -v
ruby 1.9.2p290 (2011-07-09) [i386-mingw32]
*sigh* :(

http://help.opscode.com/discussions/problems/1297-knife-windows-on-existing-chef-workstation


gem install chef
Fetching: mixlib-config-1.1.2.gem (100%)
Fetching: mixlib-cli-1.2.2.gem (100%)
Fetching: mixlib-log-1.3.0.gem (100%)
Fetching: mixlib-authentication-1.1.4.gem (100%)
Fetching: systemu-2.5.0.gem (100%)
Fetching: yajl-ruby-1.1.0.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing chef:
        ERROR: Failed to build gem native extension.

        c:/opt/jruby-1.6.7/bin/jruby.exe extconf.rb
WARNING: JRuby does not support native extensions or the `mkmf' library very well.
Check http://kenai.com/projects/jruby/pages/Home for alternatives.
creating Makefile

make
'make' is not recognized as an internal or external command,
operable program or batch file.


Gem files will remain installed in c:/opt/jruby-1.6.7/lib/ruby/gems/1.8/gems/yajl-ruby-1.1.0 for inspection.
Results logged to c:/opt/jruby-1.6.7/lib/ruby/gems/1.8/gems/yajl-ruby-1.1.0/ext/yajl/gem_make.out


  • Install chef-client-latest.msi
C:\> chef-client --version
'chef-client' is not recognized as an internal or external command,operable program or batch file.

Need to add c:\opt\opscode\chef\bin to System PATH

C:\> chef-client --version
Chef: 0.10.8

http://wiki.opscode.com/display/chef/Installing+Chef+Client+on+Ubuntu+or+Debian

http://www.opinionatedprogrammer.com/2011/06/chef-solo-tutorial-managing-a-single-server-with-chef/

~/chef/solo.json

{
    "run_list": [ "recipe[ubuntu::example-recipe]" ]
}

/var/chef-solo/cookbooks/ubuntu/recipes/example-recipe.rb
# From: http://www.opinionatedprogrammer.com/2011/06/chef-solo-tutorial-managing-a-single-server-with-chef/
# --- Install packages we need ---
package 'ntp'
package 'sysstat'
package 'apache2'

# --- Add the data partition ---
directory '/mnt/data_joliss'

mount '/mnt/data_joliss' do
  action [:mount, :enable]  # mount and add to fstab
  device 'data_joliss'
  device_type :label
  options 'noatime,errors=remount-ro'
end

# --- Set host name ---
# Note how this is plain Ruby code, so we can define variables to
# DRY up our code:
hostname = 'ubuntu'

file '/etc/hostname' do
  content "#{hostname}\n"
end

service 'hostname' do
  action :restart
end

file '/etc/hosts' do
  content "127.0.0.1 localhost #{hostname}\n"
end

# --- Deploy a configuration file ---
# For longer files, when using 'content "..."' becomes too
# cumbersome, we can resort to deploying separate files:
cookbook_file '/etc/apache2/apache2.conf'
# This will copy cookbooks/op/files/default/apache2.conf (which
# you'll have to create yourself) into place. Whenever you edit
# that file, simply run "./deploy.sh" to copy it to the server.

service 'apache2' do
  action :restart
end




ubuntu:~/chef$ sudo chef-solo -j solo.json
[Sat, 24 Mar 2012 23:03:01 -0700] INFO: *** Chef 0.10.8 ***
[Sat, 24 Mar 2012 23:03:03 -0700] INFO: Setting the run_list to ["recipe[ubuntu::example-recipe]"] from JSON
[Sat, 24 Mar 2012 23:03:03 -0700] INFO: Run List is [recipe[ubuntu::example-recipe]]
[Sat, 24 Mar 2012 23:03:03 -0700] INFO: Run List expands to [ubuntu::example-recipe]
[Sat, 24 Mar 2012 23:03:03 -0700] INFO: Starting Chef Run for ubuntu
[Sat, 24 Mar 2012 23:03:03 -0700] INFO: Running start handlers
[Sat, 24 Mar 2012 23:03:03 -0700] INFO: Start handlers complete.
[Sat, 24 Mar 2012 23:03:03 -0700] INFO: Processing package[ntp] action install (ubuntu::example-recipe line 3)
[Sat, 24 Mar 2012 23:03:24 -0700] INFO: package[ntp] installed version 1:4.2.6.p2+dfsg-1ubuntu5.1
[Sat, 24 Mar 2012 23:03:24 -0700] INFO: Processing package[sysstat] action install (ubuntu::example-recipe line 4)
[Sat, 24 Mar 2012 23:03:35 -0700] INFO: package[sysstat] installed version 9.1.7-2ubuntu1
[Sat, 24 Mar 2012 23:03:35 -0700] INFO: Processing package[apache2] action install (ubuntu::example-recipe line 5)
[Sat, 24 Mar 2012 23:04:17 -0700] INFO: package[apache2] installed version 2.2.17-1ubuntu1.5
[Sat, 24 Mar 2012 23:04:17 -0700] INFO: Processing directory[/mnt/data_joliss] action create (ubuntu::example-recipe line 8)
[Sat, 24 Mar 2012 23:04:17 -0700] INFO: directory[/mnt/data_joliss] created directory /mnt/data_joliss
[Sat, 24 Mar 2012 23:04:17 -0700] INFO: Processing mount[/mnt/data_joliss] action mount (ubuntu::example-recipe line 10)
[Sat, 24 Mar 2012 23:04:17 -0700] ERROR: mount[/mnt/data_joliss] (ubuntu::example-recipe line 10) has had an error
[Sat, 24 Mar 2012 23:04:17 -0700] ERROR: mount[/mnt/data_joliss] (/var/chef-solo/cookbooks/ubuntu/recipes/example-recipe.rb:10:in `from_file') had an error:
mount[/mnt/data_joliss] (ubuntu::example-recipe line 10) had an error: Chef::Exceptions::Mount: Device data_joliss does not exist
/usr/lib/ruby/vendor_ruby/chef/provider/mount/mount.rb:46:in `mountable?'
/usr/lib/ruby/vendor_ruby/chef/provider/mount/mount.rb:93:in `mount_fs'
/usr/lib/ruby/vendor_ruby/chef/provider/mount.rb:31:in `action_mount'
/usr/lib/ruby/vendor_ruby/chef/resource.rb:440:in `send'
/usr/lib/ruby/vendor_ruby/chef/resource.rb:440:in `run_action'
/usr/lib/ruby/vendor_ruby/chef/runner.rb:45:in `run_action'
/usr/lib/ruby/vendor_ruby/chef/runner.rb:81:in `converge'
/usr/lib/ruby/vendor_ruby/chef/runner.rb:81:in `each'
/usr/lib/ruby/vendor_ruby/chef/runner.rb:81:in `converge'
/usr/lib/ruby/vendor_ruby/chef/resource_collection.rb:94:in `execute_each_resource'
/usr/lib/ruby/vendor_ruby/chef/resource_collection/stepable_iterator.rb:116:in `call'
/usr/lib/ruby/vendor_ruby/chef/resource_collection/stepable_iterator.rb:116:in `call_iterator_block'
/usr/lib/ruby/vendor_ruby/chef/resource_collection/stepable_iterator.rb:85:in `step'
/usr/lib/ruby/vendor_ruby/chef/resource_collection/stepable_iterator.rb:104:in `iterate'
/usr/lib/ruby/vendor_ruby/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index'
/usr/lib/ruby/vendor_ruby/chef/resource_collection.rb:92:in `execute_each_resource'
/usr/lib/ruby/vendor_ruby/chef/runner.rb:76:in `converge'
/usr/lib/ruby/vendor_ruby/chef/client.rb:312:in `converge'
/usr/lib/ruby/vendor_ruby/chef/client.rb:160:in `run'
/usr/lib/ruby/vendor_ruby/chef/application/solo.rb:192:in `run_application'
/usr/lib/ruby/vendor_ruby/chef/application/solo.rb:183:in `loop'
/usr/lib/ruby/vendor_ruby/chef/application/solo.rb:183:in `run_application'
/usr/lib/ruby/vendor_ruby/chef/application.rb:67:in `run'
/usr/bin/chef-solo:24
[Sat, 24 Mar 2012 23:04:17 -0700] ERROR: Running exception handlers
[Sat, 24 Mar 2012 23:04:17 -0700] ERROR: Exception handlers complete
[Sat, 24 Mar 2012 23:04:17 -0700] FATAL: Stacktrace dumped to /var/chef-solo/chef-stacktrace.out
[Sat, 24 Mar 2012 23:04:17 -0700] FATAL: Chef::Exceptions::Mount: mount[/mnt/data_joliss] (ubuntu::example-recipe line 10) had an error: Chef::Exceptions::Mount: Device data_joliss does not exist