chef how to overwrite attribtues in json file

醉酒当歌 提交于 2019-12-13 04:07:36

问题


I'm trying to run the same recipe twice with different attributes. Is there a way to specify it in the run list? Example:

"myRecipe":{
"run-list": "recipe[test], recipe[test]"
}

and the first one should have flag=false while second one should execute with flag=true.


回答1:


No, that's not possible. You have to implement such logic in your recipe and e.g iterate over an array.




回答2:


I answered a similar question previously: The short version is, you need to modify your thinking. If you need to install software and configure it, you might do better to think about breaking it apart into two pieces.

Longer answer: have you taken a look at any of the cookbooks on the opscode community site? Many patterns recur and work that others have published could certainly be useful... Especially as you appear to be just starting out with chef.




回答3:


I've also tried using resources:

define :installx, :cmd=>'good', :upgrade=>true do
  Chef::Log.info('cmd = #{params[:cmd]}')
  if params[:upgrade]
    Chef::Log.info('upgrading...')
  else
    Chef::Log.info('installing...')
  end
end

installx resource
installx "name" do
  cmd "install 1"
  upgrade true
end

and it errors out: "ERROR: Cannot find a resource for define" This is pretty much right out of the official documentation. If anyone know what's causing this, please let me know.




回答4:


Some of the Chef cookbook are written very well in my opinion such as the visualstudio cookbook from https://github.com/daptiv/visualstudio.

I do have a case when I need to run this recipe twice. I have to install Visual Studio 2012 and 2013 on a machine to compile different source code. These versions of Visual Studio have the exact same silent install process by point to an XML file so it was easy to make it work for 2012 and 2013.

I was able to create a Chef role file to override the attributes of the visualstudio cookbook to point my private Visual Studio 2012 ISO. That was easy. Then I created another Chef role file for installing 2013 to point to a separate Visual Studio 2013 ISO. Since Chef doesn't run the recipe twice it ends up only installing Visual Studio 2013. :(

It would suck if I have to make two local copies of the "visualstudio" cookbook.



来源:https://stackoverflow.com/questions/20892059/chef-how-to-overwrite-attribtues-in-json-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!