得到了"未定义的方法`[]'为nil:NilClass"安装java Cookbook

Mor*_*rph 2 ruby java maven chef-infra vagrant

我尝试使用Chef Solo和Berkshelf建立一个流浪者vm.我想用maven cookbook."maven"依赖于"java"和"java_ark"(包含在"java"食谱中).所有这些都是由Opscode创建的.

但每次我收到此错误:

NoMethodError

-------------

undefined method `[]' for nil:NilClass




Cookbook Trace:
---------------
  /tmp/vagrant-chef-1/chef-solo-1/cookbooks/java/recipes/default.rb:21:in `from_file'
  /tmp/vagrant-chef-1/chef-solo-1/cookbooks/platform-slayer/recipes/slayer_worker.rb:2:in `from_file'


Relevant File Content:
----------------------
/tmp/vagrant-chef-1/chef-solo-1/cookbooks/java/recipes/default.rb:

 14:  # Unless required by applicable law or agreed to in writing, software
 15:  # distributed under the License is distributed on an "AS IS" BASIS,
 16:  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 17:  # See the License for the specific language governing permissions and
 18:  # limitations under the License.
 19:  #
 20:  
 21>> include_recipe "java::#{node['java']['install_flavor']}"
 22:  
 23:  # Purge the deprecated Sun Java packages if remove_deprecated_packages is true
 24:  %w[sun-java6-jdk sun-java6-bin sun-java6-jre].each do |pkg|
 25:    package pkg do
 26:      action :purge
 27:      only_if { node['java']['remove_deprecated_packages'] }
 28:    end
 29:  end
 30:
Run Code Online (Sandbox Code Playgroud)

有谁知道这个问题?如果您需要更多信息,请与我们联系.

Ste*_*n C 5

我认为问题在于node['java']评估nil.

一种可能的解决方案是node['java']['install_flavor']在cookbook或Node定义或相关的Role定义中定义属性.

但它看起来像是食谱中的一个错误,因为文档说默认值应该适用于该install_flavor属性.

  • 是的,这是对的,因为必须将配方添加为metadata.rb中的依赖项.感谢您的帮助!;) (2认同)