使用Chef在CentOS上安装Java JDK 1.8

时间:2018-08-21 17:36:14

标签: java java-8 chef devops cookbook

我正在尝试使用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 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

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

经过几次尝试(Slack Chef聊天也支持...),我解决了:我不确定这种解决方案的通用性如何,但它是否有效。

问题与命令kitchen converge的执行有关。

我注意到,当它失败并显示消息warning: conflicting chdir during another chdir block时,此生成消息(我不知道为什么……),请在食谱中查找某些目录(在我的情况下,java,{ {1}},windows等),这很奇怪。

我所做的:

  1. 提交命令homebrew
  2. 清除了我的berk缓存kitchen destroy
  3. 提交命令C:\Users\USERNAME\.berkshelf
  4. 提交命令kitchen create
  5. 如果比较错误kitchen converge,并且食谱内部生成了一些奇怪的目录,请手动将其删除。
  6. 检查是否下载了Chef超市食谱 warning: conflicting chdir during another chdir block(在我的情况下为C:\Users\USERNAME\.berkshelfhomebrew-5.0.4java-2.2.0tomcat-3.0.0
  7. 重复命令windows-5.0.0,直到没有错误发生为止

通过这种方式,在我的CentOS 7目标节点上安装了oracle java jdk 1.8

我希望这对其他人有用