1

我是 Chef 的新手,所以我的问题似乎有些不知情。

我正在运行 Chef 服务器(v11.4)。我的 Chef 工作站正在运行 MRI Ruby 1.9.3 和 gems Knife-ec2 (v0.6.4) 和 Knife-windows (v0.5.12)。

我正在尝试在安装了 Ruby 的 Amazon AWS 上设置 Windows 2008r2 服务器。我可以通过运行(在命令行窗口的 Windows 框中)静默、无人看管地手动执行此操作:

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

我想使用 Chef 来自动执行此操作。

我尝试在以下配方片段中使用 windows_batch:

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

我将配方上传到 Chef 服务器,然后运行以下命令来触发 Chef 运行:

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

在这种情况下,remote_file 工作并下载了 ruby​​ 安装程序。但是,windows_batch 挂起,安装无处可去。我知道这一点,因为当我 RDP 进入 Windows 服务器时,rubyinstaller-1.9.3-p429.exe 文件位于 c: 中。我知道安装程序挂起是因为我在刀工作站上收到一条消息,说 Ruby 安装程序已启动,但最终超时。Windows 服务器上没有安装任何东西。

然后我尝试用 windows_package 替换 windows_batch 片段。

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

我在注释掉本地源选项的情况下尝试了上面的部分,然后在注释掉远程源选项的情况下再次尝试。没有一个工作。Ruby 安装程序挂起。这是最后几行的样子:

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.

在请求超时之前一直保持这种状态。没有安装红宝石。

这导致了几个问题:

  1. 我是否遗漏了 windows_batch 或 windows_package 语法中的某些内容,从而阻止我以静默方式、无人值守和自动使用 Chef 安装 Ruby?
  2. 有没有办法准确查看命令行上正在运行哪个命令来安装 Ruby?例如日志文件、详细模式等?
  3. 有没有人使用 Chef 和 ruby​​installer 在 Windows 上安装 Ruby,你能提供一个食谱吗?
4

2 回答 2

1

通过两个非常微妙的调整解决了这个问题:

  1. 第一个调整是标题。当您使用安装程序手动安装 Ruby 时,您必须转到 Windows 控制面板,并找到 Ruby 程序将其卸载。当您找到它时,您会在已安装程序列表中看到一个非常具体的 Ruby 名称。(这是“显示名称”,它也在该已安装软件的 Windows 注册表中)。我看到了“Ruby 1.9.3-p448”。这就是 windows_package 之后必须要做的事情。并且使用该“显示名称”确保如果 Chef 再次运行,它不会重新安装相同的 Ruby(如果它已经存在)。
  2. 第二个调整是引用 Ruby 字符串。双引号会产生问题,尤其是在您不完全了解必须转义的字符时。当您使用单引号时,问题就消失了,因为单引号是非常字面的。

因此,这就是使用 Ruby 安装程序静默安装 Ruby 的有效 Chef 资源/提供程序代码的样子:

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

非常感谢 Opscode 的 Isa Farnik 在这方面的帮助。

于 2013-07-16T14:30:40.043 回答
0

您需要在 windows_package 的选项中转义 '

当前的:

options "/silent /dir='C:/Ruby193' /tasks='modpath'"

逃脱

options "/silent /dir=\'C:/Ruby193\' /tasks=\'modpath\'"

否则它会挂起尝试解析选项。

于 2013-07-10T20:41:05.400 回答