Chef-solo:未设置属性的问题

时间:2013-10-25 16:18:33

标签: chef chef-solo

伙计们,我对Chef-solo属性感到茫然。我有一堆收件人,其中一些曾经被编码为角色,而当他们作为角色时,他们大多数工作正常。例如,我曾经担任过一个角色:

name "apache"
description "Configure php5.3 and apache2 with mod_php."
run_list ( "recipe[php]", "recipe[apache2]" )

我现在有:

# "Configure php5.3 and apache2 with mod_php."
include_recipe "php"
include_recipe "apache2"

这看起来相当容易,但我现在遇到了属性问题。 “php”cookbook配方在default.rb文件中有属性,代码失败并显示错误:

NoMethodError
-------------
undefined method `[]' for nil:NilClass

在标准php cookbook中的行php / recipes / default.rb:

include_recipe "php::#{node['php']['install_method']}"

我认为是因为属性文件尚未运行,因为如果运行它,则值install_method将被设置为'package'。我不认为这个问题特定于“php”配方......虽然我想它可能是。

我无法找到任何指示运行给定属性文件的情况,除了关于按字母顺序读取文件的神秘评论,但未说明时。

例如,当使用菜谱中的任何食谱时,是否运行属性/ default.rb? 一旦使用了食谱,是否所有属性文件都被加载,无论如何? 它只是名称与正在运行的配方匹配的属性文件吗?

你知道如何调试这个吗?

编辑:添加一些错误消息:

[2013-10-26T22:44:10+00:00] DEBUG: Loading Recipe el-drupal-cookbook::apache2_mod_php via include_recipe
[2013-10-26T22:44:10+00:00] DEBUG: Found recipe apache2_mod_php in cookbook el-drupal-cookbook
[2013-10-26T22:44:10+00:00] DEBUG: Loading Recipe php via include_recipe
[2013-10-26T22:44:10+00:00] DEBUG: Found recipe default in cookbook php
[2013-10-26T22:44:10+00:00] DEBUG: filtered backtrace of compile error: /tmp/vagrant-chef-1/chef-solo-1/    cookbooks/php/recipes/default.rb:22:in `from_file',/tmp/vagrant-chef-1/chef-solo-1/cookbooks/el-drupal-    cookbook/recipes/apache2_mod_php.rb:3:in `from_file',/tmp/vagrant-chef-1/chef-solo-1/cookbooks/el-drupal-    cookbook/recipes/drupal_lamp_dev.rb:4:in `from_file'
[2013-10-26T22:44:10+00:00] DEBUG: filtered backtrace of compile error: /tmp/vagrant-chef-1/chef-solo-1/    cookbooks/php/recipes/default.rb:22:in `from_file',/tmp/vagrant-chef-1/chef-solo-1/cookbooks/el-drupal-    cookbook/recipes/apache2_mod_php.rb:3:in `from_file',/tmp/vagrant-chef-1/chef-solo-1/cookbooks/el-drupal-    cookbook/recipes/drupal_lamp_dev.rb:4:in `from_file'
[2013-10-26T22:44:10+00:00] DEBUG: backtrace entry for compile error: '/tmp/vagrant-chef-1/chef-solo-1/    cookbooks/php/recipes/default.rb:22:in `from_file''
[2013-10-26T22:44:10+00:00] DEBUG: Line number of compile error: '22'

================================================================================
Recipe Compile Error in /tmp/vagrant-chef-1/chef-solo-1/cookbooks/el-drupal-cookbook/recipes/drupal_lamp_dev    .rb
================================================================================

NoMethodError
-------------
undefined method `[]' for nil:NilClass


Cookbook Trace:
---------------
  /tmp/vagrant-chef-1/chef-solo-1/cookbooks/php/recipes/default.rb:22:in `from_file'
  /tmp/vagrant-chef-1/chef-solo-1/cookbooks/el-drupal-cookbook/recipes/apache2_mod_php.rb:3:in `from_file'
  /tmp/vagrant-chef-1/chef-solo-1/cookbooks/el-drupal-cookbook/recipes/drupal_lamp_dev.rb:4:in `from_file'


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

 15:  # Unless required by applicable law or agreed to in writing, software
 16:  # distributed under the License is distributed on an "AS IS" BASIS,
 17:  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 18:  # See the License for the specific language governing permissions and
 19:  # limitations under the License.
 20:  #
 21:  
 22>> include_recipe "php::#{node['php']['install_method']}"
 23:  
 24:  # update the main channels
 25:  php_pear_channel 'pear.php.net' do
 26:    action :update
 27:  end
 28:  

2 个答案:

答案 0 :(得分:3)

以后我发现了很多调试消息。我没有在metadata.rb文件中包含必要的“depends”行,这就是主厨需要加载属性或库文件的方法(虽然令人困惑的是它仍会找到配方)。

答案 1 :(得分:1)

当运行食谱时,会加载所有属性文件。

如果您使用的是Chef 11,则可以使用debug_value调试属性:

node.debug_value(:php, :install_method)

你能显示使用php配方的属性文件吗?它是否设置default[:php][:install_method]?您得到的错误意味着node[:php]没有价值。在此之前,日志输出是否显示任何其他错误?