1

我正在尝试设置 Chef 角色来安装 openjdk-7-jdk 和 tomcat7。我正在使用适用于javatomcat的 OpsCode 社区食谱。通过阅读文档,我相信我需要覆盖node[:java][:jdk_version]node[:tomcat][:base_version].

我创建了以下角色 JSON 文件

name "tomcat7"
run_list "recipe[tomcat]"
default_attributes(
    :java => {
        :jdk_version => "7"
    },
    :tomcat => {
        :base_version => "7",
        :java_options => "-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms1536m -Xmx1536m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m -XX:MaxPermSize=512m -XX:+DisableExplicitGC"
    }
)

当我尝试使用 Vagrant 启动 VM 时,它会出现以下错误(请注意,它同时提到了tomcat6tomcat7):

[2013-10-21T14:05:44-04:00] INFO: Processing package[sun-java6-jdk] action purge (java::default line 25)
[2013-10-21T14:05:44-04:00] INFO: Processing package[sun-java6-bin] action purge (java::default line 25)
[2013-10-21T14:05:44-04:00] INFO: Processing package[sun-java6-jre] action purge (java::default line 25)
[2013-10-21T14:05:44-04:00] INFO: Processing package[tomcat7] action install (tomcat::default line 39)
[2013-10-21T14:05:52-04:00] INFO: Processing package[tomcat7-admin] action install (tomcat::default line 39)
[2013-10-21T14:05:53-04:00] INFO: Processing directory[/usr/share/tomcat6/lib/endorsed] action create (tomcat::default line 45)
[2013-10-21T14:05:53-04:00] INFO: directory[/usr/share/tomcat6/lib/endorsed] created directory /usr/share/tomcat6/lib/endorsed
[2013-10-21T14:05:53-04:00] INFO: directory[/usr/share/tomcat6/lib/endorsed] mode changed to 755
[2013-10-21T14:05:53-04:00] INFO: Processing service[tomcat] action enable (tomcat::default line 83)
[2013-10-21T14:05:53-04:00] INFO: Processing service[tomcat] action start (tomcat::default line 83)
[2013-10-21T14:05:53-04:00] INFO: Processing template[/etc/default/tomcat7] action create (tomcat::default line 122)
[2013-10-21T14:05:53-04:00] INFO: template[/etc/default/tomcat7] backed up to /var/chef/backup/etc/default/tomcat7.chef-20131021140553
[2013-10-21T14:05:53-04:00] INFO: template[/etc/default/tomcat7] updated content
[2013-10-21T14:05:53-04:00] INFO: template[/etc/default/tomcat7] owner changed to 0
[2013-10-21T14:05:53-04:00] INFO: template[/etc/default/tomcat7] group changed to 0    [2013-10-21T14:05:53-04:00] INFO: template[/etc/default/tomcat7] mode changed to 644
[2013-10-21T14:05:53-04:00] INFO: Processing template[/etc/tomcat6/server.xml] action create (tomcat::default line 131)

================================================================================
Error executing action `create` on resource 'template[/etc/tomcat6/server.xml]'
================================================================================

Chef::Exceptions::EnclosingDirectoryDoesNotExist
------------------------------------------------
Parent directory /etc/tomcat6 does not exist.

Resource Declaration:
---------------------
# In /tmp/vagrant-chef-1/chef-solo-1/cookbooks/tomcat/recipes/default.rb

130:
131: template "#{node["tomcat"]["config_dir"]}/server.xml" do
132:   source "server.xml.erb"
133:   owner "root"
134:   group "root"
135:   mode "0644"
136:   notifies :restart, "service[tomcat]"
137: end
138:

Compiled Resource:
------------------
# Declared in /tmp/vagrant-chef-1/chef-solo-1/cookbooks/tomcat/recipes/default.rb:131:in `from_file'

template("/etc/tomcat6/server.xml") do
  mode "0644"
  retry_delay 2
  path "/etc/tomcat6/server.xml"
  retries 0
  recipe_name "default"
  owner "root"
  source "server.xml.erb"
  action "create"
  cookbook_name :tomcat
  group "root"
  backup 5
  provider Chef::Provider::Template
end

[2013-10-21T14:05:53-04:00] ERROR: Running exception handlers
[2013-10-21T14:05:53-04:00] ERROR: Exception handlers complete
[2013-10-21T14:05:53-04:00] FATAL: Stacktrace dumped to /tmp/vagrant-chef-1/chef-stacktrace.out
[2013-10-21T14:05:53-04:00] FATAL: Chef::Exceptions::EnclosingDirectoryDoesNotExist: template[/etc/tomcat6/server.xml] (tomcat::default line 131) had an error: Chef::Exceptions::EnclosingDirectoryDoesNotExist: Parent directory /etc/tomcat6 does not exist.
Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.

似乎该node[:tomcat][:base_version]属性已被覆盖,因为它正在安装 tomcat7 和 tomcat7-admin。但是,它正在创建 tomcat6 目录。

The full example can be found at https://github.com/McPolemic/tomcat_chef_example/.

Is there a rhyme or reason as to when it picks the default or my attributes?

4

1 回答 1

1

I'm pretty sure it's a bug in the recipe - if you override base_version, in some cases you also need to override config_dir.

于 2013-11-13T23:27:24.057 回答