Detect the Chef Client version in a Chef recipe

2019-07-30 08:30发布

问题:

I am upgrading my cookbooks from Chef version 12.11.18 to 13.6.4. Some version 13 specific instructions do not work in Chef version 12 and vice versa. My existing servers still use Chef Client 12, but the new servers will launch with Chef version 13 in the same environment, so the same cookbook version should work with both versions of Chef.

I need to detect the version of the Chef Client in a recipe and select the version specific code with an "if" statement. How can I read the version of the Chef Client in a Chef recipe?

回答1:

If you have Chef installed from the package version should be in node["chef_packages"]["chef"]["version"]. If this does not work, you should be able to read Chef::VERSION from recipe.