Can I reference multiple versions of a Chef cookbook?

1k views Asked by At

Is it possible to reference multiple versions of a Chef cookbook within a recipe like the following where a recipe in one cookbook (foo) references multiple versions of a recipe in another cookbook (bar) where the version variable is populated before this block?

begin
    case version
    when ""
        include_recipe "cookbook-bar"
    when "1.0.0"
        include_recipe "[email protected]"
    when "1.0.1"
        include_recipe "[email protected]"
    else
        raise "Invalid Version: " + version
    end
rescue Chef::Exceptions::CookbookNotFound
    raise "The Specified Cookbook Was Not Found: cookbook-foo-bar@" + version
end

In the metadata.rb file I have set the dependency like the following to hopefully pull in versions 1.0.0, 1.0.1, and 1.0.2 of cookbook-bar.

depends          "cookbook-bar", "<= 1.0.2"

But when I run it I still get the CookbookNotFound error for versions 1.0.0 and 1.0.1 of cookbook-bar.

1

There are 1 answers

2
Tensibai On BEST ANSWER

You can't, only one version of a cookbook will be pulled down on the node, the highest matching the dependency constraint.

If you need multiples version of a cookbook within the same run, you have a problem somewhere.