phoxd
phoxd

Reputation: 1622

Include third party resource in chef

I am trying use chef-gsettings

# ./cookbooks/my_cookbook/recipes/default.rb
include_recipe 'chef-gsettings'

Also uploaded it to Chef Server with

$ knife cookbook upload chef-gsettings

But bootstrap fails

$ knife bootstrap 192.168.1.88 -U user -i ~/.ssh/id --node-name node1 --sudo --run-list 'recipe[my_cookbook]' 
...
FATAL: Chef::Exceptions::RecipeNotFound: could not find recipe default for cookbook chef-gsettings

Upvotes: 1

Views: 102

Answers (1)

Draco Ater
Draco Ater

Reputation: 21226

As you could see, chef-gsettings cookbook does not have any recipes in it. It just provides a gsettings resource to use in your cookbook.

But here you are including chef-gsettings::default recipe (providing only cookbook name and omitting recipe, means you include ::default recipe).

# ./cookbooks/my_cookbook/recipes/default.rb
include_recipe 'chef-gsettings'

That's why the error.

FATAL: Chef::Exceptions::RecipeNotFound: could not find recipe default for cookbook chef-gsettings

You actually need to use gsettings resource in your recipe (see Usage in readme):

# ./cookbooks/my_cookbook/recipes/default.rb
gsettings "org.gnome.desktop.interface" do
  option "monospace-font-name"
  value "Monospace 14"
  user "bob"
end

If this does not work, which is possible, because you imported this cookbook as 'chef-gsettings' and not as 'gsettings', you will need to use chef-gsettings resource:

# ./cookbooks/my_cookbook/recipes/default.rb
chef-gsettings "org.gnome.desktop.interface" do  # !!! this will not work, as Ruby does not allow `-` in method names
  [...]
end

# Try using this workaround instead:
declare_resource('chef-gsettings'.to_sym, "org.gnome.desktop.interface") do
  option "monospace-font-name"
  [...]
end

Upvotes: 1

Related Questions