gpt4 book ai didi

java - 使用 Chef 在 CentOS 上安装 Java JDK 1.8

转载 作者:行者123 更新时间:2023-11-30 06:02:44 24 4
gpt4 key购买 nike

我正在尝试使用 Chef Cookbook 在 CentOS 7 上安装 Java JDK 1.8。

我在 Windows 10 上使用 Chef DK,并且已从 https://downloads.chef.io/chefdk 下载

在我的 Berksfile 中,我已经

source 'https://supermarket.chef.io'
metadata

我的Kitchen.yml如下

---
driver:
name: vagrant

provisioner:
name: chef_zero
# You may wish to disable always updating cookbooks in CI or other testing environments.
# For example:
# always_update_cookbooks: <%= !ENV['CI'] %>
always_update_cookbooks: true

verifier:
name: inspec

platforms:
- name: centos-7

suites:
- name: default
run_list:
- recipe[test::default]
verifier:
inspec_tests:
- test/integration/default
attributes:

我的metadata.rb如下

name 'test'
maintainer 'The Authors'
maintainer_email 'you@example.com'
license 'All Rights Reserved'
description 'Installs/Configures test'
long_description 'Installs/Configures test'
version '0.1.0'
chef_version '>= 12.14' if respond_to?(:chef_version)

depends 'java', '~> 2.2.0'

我的recipes/default.rb

node.default["java"]["install_flavor"] = "oracle"
node.default["java"]["jdk_version"] = "8"
node.default['java']['oracle']['accept_oracle_download_terms'] = true

include_recipe "java"

及其attributes/recipe.rb

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

当我尝试执行kitchen融合时,输出是

-----> Starting Kitchen (v1.22.0)
-----> Converging <default-centos-7>...
Preparing files for transfer
Preparing dna.json
Resolving cookbook dependencies with Berkshelf 7.0.4...
Removing non-cookbook files before transfer
Preparing validation.pem
Preparing client.rb
-----> Chef Omnibus installation detected (install only if missing)
Transferring files to <default-centos-7>
Starting Chef Client, version 14.3.37
resolving cookbooks for run list: ["test::default"]
Synchronizing Cookbooks:
- windows (5.0.0)
- homebrew (5.0.4)
- test (0.1.0)
- java (2.2.0)
Installing Cookbook Gems:
Compiling Cookbooks...

================================================================================
Recipe Compile Error in /tmp/kitchen/cache/cookbooks/test/recipes/default.rb
================================================================================

NoMethodError
-------------
undefined method `java_oracle_install' for cookbook: java, recipe: oracle :Chef::Recipe

Cookbook Trace:
---------------
/tmp/kitchen/cache/cookbooks/java/recipes/oracle.rb:40:in `from_file'
/tmp/kitchen/cache/cookbooks/java/recipes/default.rb:22:in `from_file'
/tmp/kitchen/cache/cookbooks/test/recipes/default.rb:8:in `from_file'

Relevant File Content:
----------------------
/tmp/kitchen/cache/cookbooks/java/recipes/oracle.rb:

33: version = node['java']['jdk_version'].to_s
34: tarball_url = node['java']['jdk'][version][arch]['url']
35: tarball_checksum = node['java']['jdk'][version][arch]['checksum']
36: bin_cmds = node['java']['jdk'][version]['bin_cmds']
37:
38: include_recipe 'java::set_java_home'
39:
40>> java_oracle_install 'jdk' do
41: url tarball_url
42: default node['java']['set_default']
43: checksum tarball_checksum
44: app_home java_home
45: bin_cmds bin_cmds
46: alternatives_priority node['java']['alternatives_priority']
47: retries node['java']['ark_retries']
48: retry_delay node['java']['ark_retry_delay']
49: connect_timeout node['java']['ark_timeout']

System Info:
------------
chef_version=14.3.37
platform=centos
platform_version=7.5.1804
ruby=ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
program_name=/opt/chef/bin/chef-client
executable=/opt/chef/bin/chef-client


Running handlers:
[2018-08-21T17:23:54+00:00] ERROR: Running exception handlers
[2018-08-21T17:23:54+00:00] ERROR: Running exception handlers
Running handlers complete
[2018-08-21T17:23:54+00:00] ERROR: Exception handlers complete
[2018-08-21T17:23:54+00:00] ERROR: Exception handlers complete
Chef Client failed. 0 resources updated in 04 seconds
[2018-08-21T17:23:54+00:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out
[2018-08-21T17:23:54+00:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out
[2018-08-21T17:23:54+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2018-08-21T17:23:54+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2018-08-21T17:23:54+00:00] FATAL: NoMethodError: undefined method `java_oracle_install' for cookbook: java, recipe: oracle :Chef::Recipe
[2018-08-21T17:23:54+00:00] FATAL: NoMethodError: undefined method `java_oracle_install' for cookbook: java, recipe: oracle :Chef::Recipe
>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: 1 actions failed.
>>>>>> Converge failed on instance <default-centos-7>. Please see .kitchen/logs/default-centos-7.log for more details
>>>>>> ----------------------
>>>>>> Please see .kitchen/logs/kitchen.log for more details
>>>>>> Also try running `kitchen diagnose --all` for configuration

有什么建议吗?

最佳答案

经过多次尝试(Slack Chef 聊天也支持...),我解决了:我不确定这个解决方案有多通用,但它有效。

问题是关于命令kitchen融合的执行。

我注意到,当它失败并显示消息警告:在另一个 chdir block 期间冲突 chdir 时,会生成此消息(我不知道为什么......),在 Recipe 中的一些目录(在我的情况是,javawindowshomebrew、ecc ..),这很奇怪。

我做了什么:

  1. 提交命令厨房销毁
  2. 清除了我的berks缓存C:\Users\USERNAME\.berkshelf
  3. 提交命令kitchen create
  4. 提交命令kitchen融合
  5. 如果错误警告:在另一个 chdir block 比较期间冲突 chdir,并且 Recipe 中生成了一些奇怪的目录,请删除它们(手动)。
  6. 检查 Chef 超市 Recipe 是否已下载到C:\Users\USERNAME\.berkshelf(在我的例子中homebrew-5.0.4java-2.2.0tomcat-3.0.0windows-5.0.0)
  7. 重复命令kitchen融合直到没有错误产生

这样我的CentOS 7目标节点上就已经安装了oracle java jdk 1.8

我希望这对其他人有用

关于java - 使用 Chef 在 CentOS 上安装 Java JDK 1.8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51953977/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com