# Run cookbook specifying only major version

**URL:** <https://discourse.chef.io/t/run-cookbook-specifying-only-major-version/10565>\
**Category:** Chef Infra (archive)\
**Created:** [March 13, 2017, 11:25am UTC](https://discourse.chef.io/t/run-cookbook-specifying-only-major-version/10565 "2017-03-13T11:25:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![prangan](https://avatars.discourse-cdn.com/v4/letter/p/7cd45c/32.png) [@prangan](https://discourse.chef.io/u/prangan)\
**Post date:** [March 13, 2017, 11:25am UTC](https://discourse.chef.io/t/run-cookbook-specifying-only-major-version/10565/1 "2017-03-13T11:25:44Z")

</div>

Hi,

We are planning to have two version series of the cookbooks for branching.  
We would like to call the specific major version of the cookbook wherever required.

When i specify the exact version of the cookbook, it works fine. However, at any point of time, we will not know the current version of the cookbook unless we list the latest versions and get the number.

Is there anyway to call the latest version of the cookbook specifying only the major version ?

For example, if the metadata.version is 17.1.1 on Monday and it is 17.1.8 on Friday, i would like to invoke whatever is the latest number in 17 series.

Any help would be much appreciated.

Thank you

---

<div class="post-metadata">

**Author:** ![Tensibai](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/tensibai/32/29_2.png) [@Tensibai](https://discourse.chef.io/u/Tensibai)\
**Post date:** [March 13, 2017, 3:19pm UTC](https://discourse.chef.io/t/run-cookbook-specifying-only-major-version/10565/2 "2017-03-13T15:19:43Z")

</div>

Using pessimistic version constraint: `'cookbook', '~> 17'` for example in another cookbook metadata’s depends line.

doc: [https://docs.chef.io/cookbook\_versions.html](https://docs.chef.io/cookbook_versions.html)

---

<div class="post-metadata">

**Author:** ![prangan](https://avatars.discourse-cdn.com/v4/letter/p/7cd45c/32.png) [@prangan](https://discourse.chef.io/u/prangan)\
**Post date:** [March 14, 2017, 2:55pm UTC](https://discourse.chef.io/t/run-cookbook-specifying-only-major-version/10565/3 "2017-03-14T14:55:24Z")

</div>

Thank you, I tried using this in Environment.json and invoked recipe specific to environment.

Otherwise, Is there a direct way of running the recipe with operators ? I tried called the specific version and that works, however \<, \> ,= don’t work on the the command.

---

<div class="post-metadata">

**Author:** ![Tensibai](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/tensibai/32/29_2.png) [@Tensibai](https://discourse.chef.io/u/Tensibai)\
**Post date:** [March 14, 2017, 2:58pm UTC](https://discourse.chef.io/t/run-cookbook-specifying-only-major-version/10565/4 "2017-03-14T14:58:22Z")

</div>

Not that I’m aware of, you specify a runlist of cookbooks, but not of specific version.

One workaround could be to use wrapper cookbooks just depending on your cookbook with a pessimistic limitation and named over the major you’re targeting. This way you can take advantage of the syntax in the metatdata.rb and chose on command line which cookbook you use for the run.

---

<div class="post-metadata">

**Author:** ![prangan](https://avatars.discourse-cdn.com/v4/letter/p/7cd45c/32.png) [@prangan](https://discourse.chef.io/u/prangan)\
**Post date:** [March 15, 2017, 8:58am UTC](https://discourse.chef.io/t/run-cookbook-specifying-only-major-version/10565/5 "2017-03-15T08:58:42Z")

</div>

Sorry for mentioning the word recipe there. I meant invoking **cookbook** with major version.

Thanks, idea of wrapper cookbook is nice. That will help to run the desired versions without the dependency of environment and roles.

---

<div class="post-metadata">

**Author:** ![Tensibai](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/tensibai/32/29_2.png) [@Tensibai](https://discourse.chef.io/u/Tensibai)\
**Post date:** [March 15, 2017, 9:01am UTC](https://discourse.chef.io/t/run-cookbook-specifying-only-major-version/10565/6 "2017-03-15T09:01:58Z")

</div>

Well to be “pedantic” when you add in runlist a ‘cookbook’ entry it resolve to the recipe ‘cookbook::default’ so that’s ok 🙂

The wrapper is the only way I’m aware of which can solve what you’re after. Maybe policyfiles can also, but I didn’t dig into them.
