如何使用execute更新java的替代品? [英] How to use chef to update-alternatives for java using execute?

查看:233
本文介绍了如何使用execute更新java的替代品?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到语法错误,我不确定如何解决它们。在角色文件中,我定义了以下内容:

I am having syntax errors and I am unsure how to resolve them. In the roles file I have defined the fallowing:

default_attributes(
  'jdk' => {
    'version' => '1.8.0_31'
  },
  'java' => {
    'home' => '/usr/lib/jvm/jdk1.8.0_31'
  },
)

我尝试使用java home in以下,但无法运行

I try to use the java home in the following, but it fails to run

execute "update_alt_java" do
  command "update-alternatives --install "/usr/bin/java" "java" "#{node['java']['home']}/bin/java" 1"
  action :creates
end

我收到以下错误

SyntaxError
-----------
/etc/chef/src/cookbooks/jdk/recipes/default.rb:50: syntax error, unexpected tSTRING_BEG, expecting keyword_do or '{' or '('
...tives --install "/usr/bin/java" "java" "#{node['java']['home...
...                               ^
/etc/chef/src/cookbooks/jdk/recipes/default.rb:50: syntax error, unexpected tIDENTIFIER, expecting keyword_end
...--install "/usr/bin/java" "java" "#{node['java']['home']}/bi...


推荐答案

您使用社区 java cookbook

它包含一个用于此目的的LWRP:

It includes an LWRP for this purpose:

# set alternatives for java and javac commands
java_alternatives "set java alternatives" do
    java_location '/usr/local/java'
    bin_cmds ["java", "javac"]
    action :set
end



更新:my_java包装食谱示例



以下是名为my_java的示例菜谱,旨在在Ubuntu上安装oracle JDK:

Update: "my_java" wrapper cookbook example

The following is a sample cookbook called "my_java" designed to install the oracle JDK on Ubuntu:

├── attributes
│   └── java.rb   <-- Used for java cookbook attribute overrides
├── Berksfile
├── Berksfile.lock
├── metadata.rb
├── README.md
└── recipes
    └── default.rb

在运行厨师之后,oracle JDK被安装

After running chef the oracle JDK is intalled

$ java -version
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)

注意:


  • 这本食谱依赖于覆盖属性。这可以从厨师环境或角色轻松完成。

name             'my_java'
maintainer       'Mark O''Connor'
maintainer_email 'XXXXXXXXXXXXXXX'
license          'All rights reserved'
description      'Installs/Configures my_java'
long_description 'Installs/Configures my_java'
version          '0.1.0'

depends "apt"
depends "java"



属性/ java.rb



attribute/java.rb

normal['java']['jdk_version'] = '8'
normal['java']['install_flavor'] = 'oracle'
normal['java']['oracle']['accept_oracle_download_terms'] = true

注意:


  • 默认情况下,java将安装openJDK。这些覆盖指定OracleJDK的v8

include_recipe "apt"
include_recipe "java"

备注:


  • 显然,apt食谱仅适用于基于Debian的linux。这个配方也需要进行小调整以处理redhat。

这篇关于如何使用execute更新java的替代品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆