【问题标题】:Can't Get Basic Chef Scenario Working On Windows With Cookbooks无法使用食谱在 Windows 上工作的基本厨师场景
【发布时间】:2016-08-08 04:44:49
【问题描述】:

在 Windows 服务器上安装了 Chef 客户端和 DK,尝试在本地模式下使用具有 Windows 功能的配方

运行以下

C:\chef>mkdir cookbooks
C:\chef>cd cookbooks
C:\chef\cookbooks>chef generate cookbook test_chef

将以下内容放入 C:\chef\cookbooks\test_chef\Berksfile

source 'https://supermarket.chef.io'

metadata
cookbook 'windows', '~> 1.39.2'

将以下内容放入 C:\chef\cookbooks\test_chef\recipes\default.rb

windows_feature "NetFx3" do
  action :install
  all true
end

运行以下

C:\chef\cookbooks\test_chef>berks vendor install
Resolving cookbook dependencies...
Fetching 'test_chef' from source at .
Using chef_handler (1.3.0)
Using test_chef (0.1.0) from source at .
Using windows (1.39.2)
Vendoring chef_handler (1.3.0) to install/chef_handler
Vendoring test_chef (0.1.0) to install/test_chef
Vendoring windows (1.39.2) to install/windows

C:\chef\cookbooks\test_chef>chef-client --local-mode --runlist 'recipe[test_chef]
[2016-04-16T04:44:06+00:00] WARN: No config file found or specified on command line, using command line options.
Starting Chef Client, version 12.8.1
resolving cookbooks for run list: ["test_chef"]
Synchronizing Cookbooks:
  - test_chef (0.1.0)
Installing Cookbook Gems:
Compiling Cookbooks...
←[0m
================================================================================
Recipe Compile Error in C:/Users/admin/.chef/local-mode-cache/cache/cookbooks/test_chef/recipes/default.rb
================================================================================

NoMethodError
-------------
No resource or method named `windows_feature' for `Chef::Recipe "default"'

←[0m
Running handlers:
[2016-04-16T04:44:10+00:00] ERROR: Running exception handlers
Running handlers complete
[2016-04-16T04:44:10+00:00] ERROR: Exception handlers complete
Chef Client failed. 0 resources updated in 03 seconds
[2016-04-16T04:44:10+00:00] FATAL: Stacktrace dumped to C:/Users/admin/.chef/local-mode-cache/cache/chef-stacktrace.out
[2016-04-16T04:44:10+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2016-04-16T04:44:10+00:00] FATAL: NoMethodError: No resource or method named `windows_feature' for `Chef::Recipe "defau
lt"'

因此,即使我正在使用 berks vendor install 并且它已成功将 windows 食谱下载到 cookbooks 文件夹,厨师客户端仍然在尝试使用 windows_feature 时失败。

我基本上是在逐字跟踪一个在线示例。

【问题讨论】:

    标签: chef-infra chef-recipe windows-server


    【解决方案1】:

    而不是将以下行添加到您的 Berksfile

    cookbook 'windows', '~> 1.39.2'
    

    将此行添加到您的metadata.rb:

    depends 'windows', '~> 1.39.2'
    

    Berkshelf 仍然可以从超市下载这个依赖项(因为它被添加为source),但chef-client 不会在你的食谱之前加载 windows 食谱,因此windows_feature 资源将是已知的。

    【讨论】:

    • 这有什么实际区别?
    • 缺少食谱:------------------ 没有这样的食谱:windows
    • 我还需要 berksfile 什么的吗?
    • 所以我做了一些供应商食谱,然后是厨师客户端,现在我得到了未初始化的常量 Chef::Provider::WindowsFeature::ServerManagerCmd
    • 如前所述,Berkshelf 将从定义的来源(即 Chef 超市)下载食谱。这包含了 metadata.rb 中指定的说明书的依赖关系。在执行chef-client 时,它将在chef run 的编译阶段加载所有cookbook 的资源,从而使它们可用于所有cookbook。这就是为什么您需要在 metadata.rb 中将其指定为依赖项。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-03
    • 1970-01-01
    • 2013-02-18
    相关资源
    最近更新 更多