问题
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.
来源:https://stackoverflow.com/questions/49462061/detect-the-chef-client-version-in-a-chef-recipe