[英]Install Java JDK 1.8 on CentOS using Chef
I'm trying to install Java JDK 1.8 on CentOS 7 using a Chef Cookbook.我正在尝试使用 Chef Cookbook 在 CentOS 7 上安装 Java JDK 1.8。
I'm using Chef DK on Windows 10 and I've donloaded from https://downloads.chef.io/chefdk我在 Windows 10 上使用 Chef DK,我从https://downloads.chef.io/chefdk 下载
In my Berksfile
I've在我的Berksfile
中
source 'https://supermarket.chef.io'
metadata
My Kitchen.yml
is the follow我的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:
My metadata.rb
is the follow我的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'
My recipes/default.rb
我的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"
and its attributes/recipe.rb
及其attributes/recipe.rb
default['java']['install_flavor'] = 'oracle'
default['java']['jdk_version'] = '8'
default['java']['oracle']['accept_oracle_download_terms'] = true
When I try to execute kitchen converge
the output is当我尝试执行kitchen converge
,输出是
-----> 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
Any suggestions?有什么建议?
After several attempts (supported also by the Slack Chef chat ...), I've solved: I'm not sure how general is this solution but it works.经过几次尝试(也得到了 Slack Chef 聊天的支持......),我已经解决了:我不确定这个解决方案有多普遍,但它有效。
The problem is a about execution of the command kitchen converge
.问题是关于执行命令kitchen converge
。
I've noticed that when it fails with the message warning: conflicting chdir during another chdir block
this generate (I don't kno why ...), INSIDE the cookbook some directories (in my case, java
, windows
, homebrew
, ecc .. ), and this was quite strange.我注意到,当它失败并显示消息warning: conflicting chdir during another chdir block
这会生成(我不知道为什么......),在食谱中一些目录(在我的情况下, java
, windows
, homebrew
, ecc .. ),这很奇怪。
What I've done:我所做的:
kitchen destroy
提交命令kitchen destroy
C:\\Users\\USERNAME\\.berkshelf
清除了我的 berks 缓存C:\\Users\\USERNAME\\.berkshelf
kitchen create
提交命令kitchen create
kitchen converge
提交命令kitchen converge
warning: conflicting chdir during another chdir block
compare and some strange directory is generated inside the cookbook, delete them (MANUALLY).如果错误warning: conflicting chdir during another chdir block
比较warning: conflicting chdir during another chdir block
中生成了一些奇怪的目录,请删除它们(手动)。C:\\Users\\USERNAME\\.berkshelf
(in my case homebrew-5.0.4
, java-2.2.0
, tomcat-3.0.0
and windows-5.0.0
)检查 Chef 超市食谱是否已下载到C:\\Users\\USERNAME\\.berkshelf
(在我的情况下homebrew-5.0.4
、 java-2.2.0
、 tomcat-3.0.0
和windows-5.0.0
)kitchen converge
until no error is generated重复命令kitchen converge
直到没有错误产生In this way oracle java jdk 1.8 has been installed on my CentOS 7 target node这样oracle java jdk 1.8就已经安装在我的CentOS 7目标节点上了
I hope this could be useful for others我希望这对其他人有用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.