为什么应用或忽略厨师属性?

时间:2013-10-21 18:38:28

标签: java tomcat chef

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

我创建了following role JSON file

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时,会出现以下错误(请注意,它提到了 tomcat6 tomcat7 ):

[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目录。

完整示例可在https://github.com/McPolemic/tomcat_chef_example/找到。

在选择默认值或我的属性时是否有押韵或理由?

1 个答案:

答案 0 :(得分:1)

我很确定这是配方中的一个错误 - 如果你覆盖base_version,在某些情况下你还需要覆盖config_dir。