ruby - Check version of Python from Chef CookBook and install package according to the outcome -
i need write chef cookbook install packages according version of python installed in system.
is possible have following logic in chef recipe:
python_version = `python -v` # check python version if python_version == '2.6.6' package 'package_a' # install package_a using chef package resource elsif python_version == '3.3.5' package 'package_b' # install package_b using chef package resource else break # stop execution of cookbook end
thank in advance!
short answer yes.
you should use shell_out!('python -v').stdout().chomp()
instead of backticks.
but information exist in node automatic attributes don't have call python -v
:
ohai languages
return:
{ "python": { "version": "2.7.3", "builddate": "jun 22 2015, 19:33:41" }, "perl": { "version": "5.14.2", "archname": "x86_64-linux-gnu-thread-multi" }, "c": { "gcc": { "version": "4.6.3", "description": "gcc version 4.6.3 (ubuntu/linaro 4.6.3-1ubuntu5) " } } }
so should able write in recipe:
python_version = node['languages']['python']['version'] if python_version == '2.6.6' package 'package_a' # install package_a using chef package resource elsif python_version == '3.3.5' package 'package_b' # install package_b using chef package resource else raise # stop execution of cookbook end
to stop chef run, need use raise
the documentation
Comments
Post a Comment