centos – Chef-Solo“undefined方法`[]’为nil:NilClass”

我刚刚安装了一个新的CentOS 6.3 VM并禁用了SE Linux.下面是我运行安装 Ruby,Chef Solo并尝试配置VM的确切脚本:
#!/bin/bash
#
# Install chef-solo if it doesn't exist,then provision the server.
#
CHEF_FILE="https://dl.dropBox.com/u/4204671/LiquidCompass/lc-chef.tar.gz"

if [ "$#" -eq 0 ]; then
    echo "You must provide the type of server this is. (Eg: production-api,qa-api,development)"
    exit 1
fi

if [ ! -x "/usr/bin/chef-solo" ]; then
    rpm -Uvh http://rbel.frameos.org/rbel6
    yum install -y ruby ruby-devel ruby-ri ruby-rdoc ruby-shadow gcc gcc-c++ automake autoconf make curl dmidecode

    cd /tmp
    curl -O http://production.cf.rubygems.org/rubygems/rubygems-1.8.10.tgz
    tar zxf rubygems-1.8.10.tgz
    cd rubygems-1.8.10
    ruby setup.rb --no-format-executable

    gem install chef --no-ri --no-rdoc
fi

if [ -d "/etc/chef" ]; then
    rm -rf /etc/chef
fi

if [ -d "/tmp/lc-chef" ]; then
    rm -rf /tmp/lc-chef*
fi

mkdir /etc/chef 

echo "file_cache_path \"/tmp/lc-chef/chef-solo\"
cookbook_path \"/tmp/lc-chef/cookbooks\"
role_path \"/tmp/lc-chef/roles\"
json_attribs \"/etc/chef/node.json\"" > /etc/chef/solo.rb

echo "{
    \"name\": \"$1\",\"normal\": {
        \"company\": \"Liquid Compass LLC\",\"tags\": []
    },\"chef_environment\": \"_default\",\"run_list\": [
        \"role[$1]\"
    ]
}" > /etc/chef/node.json

cd /tmp
curl -O $CHEF_FILE
tar zxf lc-chef.tar.gz

chef-solo -c /etc/chef/solo.rb

不幸的是,正如我收到的脚本运行:

[2012-12-05T17:39:27-07:00] INFO: Start handlers complete.

================================================================================
Recipe Compile Error in /tmp/lc-chef/cookbooks/liquidcompass/recipes/PHP.rb
================================================================================

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

Cookbook Trace:
---------------
  /tmp/lc-chef/cookbooks/liquidcompass/recipes/PHP.rb:20:in `from_file'

Relevant File Content:
----------------------
/tmp/lc-chef/cookbooks/liquidcompass/recipes/PHP.rb:

 13:  # Unless required by applicable law or agreed to in writing,software
 14:  # distributed under the License is distributed on an "AS IS" BASIS,15:  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,either express or implied.
 16:  # See the License for the specific language governing permissions and
 17:  # limitations under the License.
 18:  #
 19:  
 20>> PHP_url                      = "http://us.PHP.net/distributions/PHP-#{node['PHP']['version']}.tar.gz"
 21:  node.set['PHP']['prefix']    = "/opt/PHP-#{node['PHP']['version']}"
 22:  node.set['PHP']['conf_path'] = "#{node['PHP']['dir']}/PHP.ini"
 23:  node.set['PHP']['configure_flags'] = [
 24:      "--prefix=#{node['PHP']['prefix']}",25:      "--with-config-file-path=#{node['PHP']['dir']}",26:      "--with-config-file-scan-dir=#{node['PHP']['dir']}/conf.d",27:      "--with-curl",28:      "--with-pear",29:      "--with-gd",

因此,在尝试加载节点[‘PHP’] [‘version’]时看起来很窒息.这是在我的/tmp/lc-chef/cookbooks/liquidcompass/attributes/default.rb中定义的:

default['PHP']['version']             = "5.4.9"

因此看起来Chef要么没有加载属性文件,要么出现其他错误.不完全确定如何找到这个.

运行:

> RubyGems 1.8.10
>厨师10.16.2

最好的祝福,
安德鲁

顺便说一句,这是堆栈跟踪:

Generated at Wed Dec 05 17:39:27 -0700 2012
NoMethodError: undefined method `[]' for nil:NilClass
/tmp/lc-chef/cookbooks/liquidcompass/recipes/PHP.rb:20:in `from_file'
/usr/lib64/ruby/gems/1.8/gems/chef-10.16.2/bin/../lib/chef/cookbook_version.rb:558:in `load_recipe'
/usr/lib64/ruby/gems/1.8/gems/chef-10.16.2/bin/../lib/chef/mixin/language_include_recipe.rb:46:in `load_recipe'
/usr/lib64/ruby/gems/1.8/gems/chef-10.16.2/bin/../lib/chef/mixin/language_include_recipe.rb:33:in `include_recipe'
/usr/lib64/ruby/gems/1.8/gems/chef-10.16.2/bin/../lib/chef/mixin/language_include_recipe.rb:27:in `each'
/usr/lib64/ruby/gems/1.8/gems/chef-10.16.2/bin/../lib/chef/mixin/language_include_recipe.rb:27:in `include_recipe'
/usr/lib64/ruby/gems/1.8/gems/chef-10.16.2/bin/../lib/chef/run_context.rb:79:in `load'
/usr/lib64/ruby/gems/1.8/gems/chef-10.16.2/bin/../lib/chef/run_context.rb:75:in `each'
/usr/lib64/ruby/gems/1.8/gems/chef-10.16.2/bin/../lib/chef/run_context.rb:75:in `load'
/usr/lib64/ruby/gems/1.8/gems/chef-10.16.2/bin/../lib/chef/client.rb:198:in `setup_run_context'
/usr/lib64/ruby/gems/1.8/gems/chef-10.16.2/bin/../lib/chef/client.rb:418:in `do_run'
/usr/lib64/ruby/gems/1.8/gems/chef-10.16.2/bin/../lib/chef/client.rb:176:in `run'
/usr/lib64/ruby/gems/1.8/gems/chef-10.16.2/bin/../lib/chef/application.rb:140:in `run_chef_client'
/usr/lib64/ruby/gems/1.8/gems/chef-10.16.2/bin/../lib/chef/application/solo.rb:224:in `run_application'
/usr/lib64/ruby/gems/1.8/gems/chef-10.16.2/bin/../lib/chef/application/solo.rb:216:in `loop'
/usr/lib64/ruby/gems/1.8/gems/chef-10.16.2/bin/../lib/chef/application/solo.rb:216:in `run_application'
/usr/lib64/ruby/gems/1.8/gems/chef-10.16.2/bin/../lib/chef/application.rb:72:in `run'
/usr/lib64/ruby/gems/1.8/gems/chef-10.16.2/bin/chef-solo:25
/usr/bin/chef-solo:19:in `load'
/usr/bin/chef-solo:19
chef solo不支持属性.

您将需要在node目录下放置一个node.json,该目录以.json形式列出属性.

所以在你的情况下:

{
    "PHP": {
      "version": "5.4.9"
     }
}

如果要使用.rb格式的属性/任何属性,则需要使用chef-server / chef-client.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Centos下搭建性能监控Spotlight
CentOS 6.3下Strongswan搭建IPSec VPN
在CentOS6.5上安装Skype与QQ
阿里云基于centos6.5主机VPN配置
CentOS 6.3下配置multipah
CentOS安装、配置APR和tomcat-native
centos6.5下postgres-XC集群安装与配置
CentOS 6使用openssl搭建根CA
CentOS6.6中安装VNC server
CentOS下更新Python最新版本
Centos安装pycurl
CentOS 7 安装PostGIS
CentOS 7.1PXE网络自动化安装
CentOS下ffmpeg与第三方编码编译安装
CentOS 6.4安装配置squid
CentOS6.5 安装配置drbd
CentOS6.4 安装jenkins
centos安装增强工具
CentOS6.4安装配置redis
CentOS 6上部署OpenVPN Server