Search code examples
chef-infrarecipe

Is it possible with chef 'include_recipe ' to append cookbook version?


i know we can include version when we run cookbook like

    chef-client -o "recipe[mycookbook@0.1.1]"

How can version can be appended when doing include_recipe

    include_recipe "apache2::mod_ssl"@version?

Solution

  • This isn't possible using include_recipe in the Chef Recipe DSL. Your options for supplying a particular version are using:

    • the runlist in a role or on a node, e.g. "recipe[mycookbook@0.1.1]"
    • an environment pinning a cookbook, e.g.:

      cookbook_versions({ "nginx" => "<= 1.1.0", "apt" => "= 0.0.1" })

    • the metadata.rb file in a cookbook, e.g. depends 'apt', '1.2.3'.

    Since you're looking to pin a version from within a cookbook, why not declare it in metadata.rb? That will have a direct effect on the include_recipe statement you're using, forcing that include to use the version declared in your metadata.

    In your example, that would be:

    depends 'mycookbook, '0.1.1'
    

    Or to use the apache example, in your metadata.rb file:

    depends 'apache2', 'version'
    

    And then in your recipe:

    include_recipe "apache2::mod_ssl"