1
votes

Installed Chef client and DK on a Windows Server, trying to use a recipe with a Windows feature in local mode

Ran the following

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

Put the following in C:\chef\cookbooks\test_chef\Berksfile

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

metadata
cookbook 'windows', '~> 1.39.2'

Put the following in C:\chef\cookbooks\test_chef\recipes\default.rb

windows_feature "NetFx3" do
  action :install
  all true
end

ran the following

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"'

So, even though I'm using berks vendor install and it's successfully downloading the windows cookbook to the cookbooks folder, the chef client still bombs out trying to use windows_feature.

I'm basically following an online example verbatim.

1

1 Answers

1
votes

Instead of adding the following line to your Berksfile

cookbook 'windows', '~> 1.39.2'

add this line to your metadata.rb:

depends 'windows', '~> 1.39.2'

Berkshelf will still be able to download this dependency from the supermarket (as it is added as source), but not also chef-client will load the windows cookbook prior to your cookbook and thus the windows_feature resource will be known.