chef-infrachef-windows

Chef: Windows 2008r2 node: Can't install Ruby with rubyinstaller


I'm new to Chef, so my question may seem somewhat uninformed.

I'm running a Chef server (v11.4). My Chef workstation is running MRI Ruby 1.9.3 and gems knife-ec2 (v0.6.4) and knife-windows (v0.5.12).

I'm trying to set up a Windows 2008r2 server on Amazon AWS with Ruby installed. I'm able to do this silently, unattended, and manually by running (on the Windows box in a command line window):

C:\> C:/rubyinstaller-1.9.3-p429.exe /silent /dir='c:\Ruby193' /tasks=’modpath’

I would like to use Chef to automate this.

I have tried using windows_batch in the following recipe fragment:

remote_file File.join("C:","rubyinstaller-1.9.3-p429.exe") do
    source "http://mybucketxxx.s3-website-us-east-1.amazonaws.com/rubyinstaller-1.9.3-p429.exe"
    not_if {::File.exists?(File.join("c:","rubyinstaller-1.9.3-p429.exe"))}
end  

windows_batch "install_ruby" do
    cwd "C:/"
    code "C:/rubyinstaller-1.9.3-p429.exe /silent /dir=\'c:/Ruby193' /tasks=’modpath’"
    only_if {::File.exists?(File.join("c:","rubyinstaller-1.9.3-p429.exe"))}
    not_if {::File.exists?(File.join("c:", "Ruby193", "bin", "ruby.exe"))}
end

I uploaded the recipe to the Chef server, and then ran the following to trigger a Chef run:

> knife winrm 'ec2-50-xx-xx-124.amazonaws.com' 'chef-client -c c:/chef/client.rb' -m -x Administrator -P 'password'

In this situation, the remote_file works and the ruby installer is downloaded. However, the windows_batch hangs and the installation goes nowhere. I know this because when I RDP'ed into the Windows server, the rubyinstaller-1.9.3-p429.exe file was sitting there in c:. And I knew that the installer hung because I got a message on the knife workstation saying that the Ruby installer had started, but it eventually timed out. And nothing was installed on the Windows server.

I then tried replacing the windows_batch fragment with windows_package.

windows_package "rubyinstaller-1.9.3-p429" do
    #source "C:/rubyinstaller-1.9.3-p429.exe"
    source "http://mybucketxxx.s3-website-us-east-1.amazonaws.com/rubyinstaller-1.9.3-p429.exe"
    options "/silent /dir='C:/Ruby193' /tasks='modpath'"
    installer_type :inno
    action :install
end

I tried the part above with the local source option commented out, and then tried it again with the remote source option commented out. Neither one worked. The Ruby installer hung. This is what the last few lines looked like:

ec2-50-xx-xx-124.amazonaws.com [2013-07-05T13:00:21+00:00] INFO: Processing windows_package[rubyinstaller-1.9.3-p429] action install (myrecipe::default line 53)
DEBUG: :relay_output_from_backend => ["ec2-50-xx-xx-124.amazonaws.com", "[2013-07-05T13:00:21+00:00] INFO: Installing windows_package[rubyinstaller-1.9.3-p429] version latest\r\n"]
ec2-50-xx-xx-124.amazonaws.com [2013-07-05T13:00:21+00:00] INFO: Installing windows_package[rubyinstaller-1.9.3-p429] version latest
DEBUG: :relay_output_from_backend => ["ec2-50-xx-xx-124.amazonaws.com", "[2013-07-05T13:00:21+00:00] INFO: Starting installation...this could take awhile.\r\n"]
ec2-50-xx-xx-124.amazonaws.com [2013-07-05T13:00:21+00:00] INFO: Starting installation...this could take awhile.

It stays like this until the request times out. Ruby is not installed.

This leads to a few questions:

  1. Am I missing something in the windows_batch or windows_package syntaxes which prevents me from installing Ruby silently, unattended, and automatically using Chef?
  2. Is there a way to see exactly which command is being run on the command line to install Ruby? e.g. Log files, verbose modes, etc?
  3. Has anybody installed Ruby on Windows using Chef and the rubyinstaller, and can you provide a recipe?

Solution

  • This problem was solved with two very subtle tweaks:

    1. The first tweak was with the title. When you install Ruby by hand using the installer, you have to go to the Windows Control Panel, and find the Ruby program to uninstall it. When you find it, you will see a very specific name for Ruby in the list of installed programs. (This is the "Display Name", and it is also in the Windows Registry for that piece of installed software). I saw "Ruby 1.9.3-p448". That is what has to go after windows_package. And using that "Display Name" ensures that if Chef runs again, it won't re-install the same Ruby if it is already present.
    2. The second tweak was with the quoting of Ruby strings. Double quotes create problems, especially if you don't fully understand which characters have to be escaped. When you use single quotes, problems disappear because single quoting is very literal.

    Therefore, this is what the working Chef resource/provider code, which silently installs Ruby using the Ruby installer, looks like:

    windows_package "Ruby 1.9.3-p448" do
        source File.join("C:", "rubyinstaller-1.9.3-p448.exe")
        options '/dir="C:/Ruby193" /tasks="modpath"'
        installer_type  :inno
        action :install
    end
    

    Many thanks to Isa Farnik from Opscode for help on this one.