2

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

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”食谱在其 default.rb 文件中有属性,代码失败并出现错误:

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

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

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

我认为这是因为属性文件尚未运行,因为如果运行,值 install_method 将被设置为“包”。我不认为这个问题是特定于“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:  
4

2 回答 2

3

后来我发现了很多调试消息。我省略了在 metadata.rb 文件中包含必要的“依赖”行,这是 chef 计算出它需要加载属性或库文件的方式(尽管令人困惑的是它仍然会找到配方)。

于 2013-10-28T12:23:45.360 回答
1

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

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

node.debug_value(:php, :install_method)

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

于 2013-10-26T13:29:48.693 回答