简体   繁体   English

如何使用json覆盖在Chef Cookbook中安装Java 7

[英]How to install java 7 in chef cookbook using json override

I have a web server role in my chef recipe like so 我的厨师食谱中有一个网络服务器角色,就像这样

name "webserver"

'nginx' => {
   'port' => "80"
},
'java' => {
   'openjdk_version' => 7
}

Berksfile Berksfile

cookbook "java"

I am trying to install java 7 - cannot seem to find a example of doing this inside a json override. 我正在尝试安装Java 7-似乎找不到在json覆盖内执行此操作的示例。

Current error is ERROR: Option version must be a kind of [String, Array]! 当前错误为ERROR:选项版本必须为[String,Array]! You passed 8. 您通过了8。

Thanks 谢谢

You do not need to override anything if you're using a role, just set the openjdk_version attribute as part of the default_attributes section of the role. 如果您使用的是角色,则无需覆盖任何内容,只需将openjdk_version属性设置为角色的default_attributes部分中的一部分即可。 That attribute is set to nil in the cookbook's attributes/default.rb so you only need to set it by following Chef's normal order of precedence . 该属性在本食谱的attributes/default.rb设置为nil ,因此您只需要遵循Chef的正常优先顺序进行设置即可

Example (JSON): 范例(JSON):

{
  "name": "webserver",
  "default_attributes": {
    "nginx": {
        "port": "80"
    },
    "java": {
      "openjdk_version": "7"
    }
  }
}

Same thing using the Ruby DSL: 使用Ruby DSL也是一样:

name "webserver"
default_attributes => {
  "nginx" => {
    "port" => "80"
  },
  "java" => {
    "openjdk_version" => "7"
  }
}

If you're using a wrapper cookbook of some kind, you could also set the attribute via that cookbook's attributes file(s), eg: default[:java][:openjdk_version] = "7" 如果您使用某种包装食谱,则还可以通过该食谱的属性文件设置属性,例如: default[:java][:openjdk_version] = "7"

This ERROR: Option version must be a kind of [String, Array]! You passed 8. ERROR: Option version must be a kind of [String, Array]! You passed 8. ERROR: Option version must be a kind of [String, Array]! You passed 8. error you're getting is because you're setting the attribute as an integer, not a string. ERROR: Option version must be a kind of [String, Array]! You passed 8.错误,因为您将属性设置为整数,而不是字符串。 If you look at the cookbook's code , you can see where the version option is called. 如果您查看食谱的代码 ,则可以看到在哪里调用了version选项。 I've honestly never used that option but it sounds like it wants a string, and the examples support that notion (see the Chef docs for the package resource -- I can't post the link because I already have too many links in this post). 老实说,我从未使用过该选项,但听起来好像它想要一个字符串,并且示例支持该概念(有关软件包资源,请参见Chef文档-我无法发布链接,因为我已经在其中包含了太多链接)发布)。

As for using Berkshelf, keep in mind Berkshelf is for resolving dependencies and making your life easier when it comes to managing said dependencies and uploading them to your node or your Chef server. 至于使用Berkshelf,请记住Berkshelf用于解决依赖关系,并使您在管理所述依赖关系并将其上载到您的节点或Chef服务器时更加轻松。 It's not used for setting Chef attributes. 它不用于设置Chef属性。

I hope this helps! 我希望这有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM