Question

We can already override Cookbook Attributes in a Role or Node Object. What about Recipes? Can we use resources (LWRP) provided in a Cookbook without having to use a Cookbook Wrapper?

For instance, I'd like to install Jenkins with some plugins. The Jenkins cookbook shows that there's an attribute that can be used

node['jenkins']['server']['plugins']

It is however limited in only allowing plugin name and version. There is also a Resource documented in the Cookbook that seems to do what I want. Eg:

jenkins_plugin 'custom_plugin' do
  action :install
  version '0.3'
  url 'http://myrepo/jenkins/plugins/0.3/custom_plugin.hpi'
end

Do I need to create a whole Wrapper Cookbook and put this code in the /recipes/default.rb just to add this functionality to a Role or Node? This seems to be overkill.

Was it helpful?

Solution

When using any community cookbook, you should always read the recipes in depth as well. You would notice that the jenkins::server recipe allows you to set url in that hash as well as name and version.

In this particular case, you could override attributes like so:

node.override['jenkins']['server']['plugins'] = [
  {
    'name' => 'custom_plugin', 
    'version' => '0.3', 
    'url' => 'http://myrepo/jenkins/plugins/0.3/custom_plugin.hpi'
  }]

In the general case however, if this recipe wasn't flexible like this, then you would have to create a cookbook, that depends on the other cookbook (you don't have to execute the recipes, just depend on it), and define the resources using the LWRP in your own recipe.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top