【问题标题】:Chef-solo: issues with unset attributesChef-solo:未设置属性的问题
【发布时间】:2013-10-28 20:23:45
【问题描述】:

伙计们,我对 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:  

【问题讨论】:

    标签: chef-infra chef-solo


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

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

      node.debug_value(:php, :install_method)
      

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

      【讨论】:

      • 我认为简短的回答是否定的,我不能...... solo.rb -j dna.json" 再次运行配置,它以同样的方式失败。然后我编辑了 cookbook/php/recipes/default.php 以添加您在开头建议的行。又跑厨师了。运行失败,没有打印任何附加信息(与最初的原因相同)。注释掉文件的其余部分并重试,它仍然失败(后来,因为我已经注释掉了 pear_php 定义)。仍然没有调试值。不知道该尝试什么。
      • 只是为了确认一下:在注释掉之后,我确实看到了一条关于正在加载 php 配方的消息,但仅此而已。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-16
      相关资源
      最近更新 更多