2012-12-06 29 views
6

मैंने अभी एक नया CentOS 6.3 VM और अक्षम SELinux स्थापित किया है।शेफ-सोलो "अपरिभाषित विधि '[]' शून्य के लिए: नील क्लास"

#!/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", 

तो यह की तरह लग रहा नीचे दिए गए सटीक स्क्रिप्ट है कि मैं रूबी, बावर्ची सोलो स्थापित करने के लिए भाग गया, और प्रावधान करने का प्रयास किया वीएम है यह node['php']['version'] लोड करने की कोशिश करने पर जोर दे रहा है। यह मेरा साथ /tmp/lc-chef/cookbooks/liquidcompass/attributes/default.rb में परिभाषित किया गया है:

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

तो ऐसा लगता है कि या तो बावर्ची नहीं गुण फ़ाइल लोड है, या कुछ और गलत है। बिल्कुल यह सुनिश्चित नहीं है कि इसे कैसे ढूंढें या नहीं।

रनिंग:

  • 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 

उत्तर

3

शेफ एकल डिफ़ॉल्ट विशेषताओं का समर्थन नहीं करता है।

आपको अपने नोड्स निर्देशिका के तहत एक node.json को एक साथ रखने की आवश्यकता होगी जो .json रूप में विशेषताओं को सूचीबद्ध करता है।

तो आपके मामले में:

{ 
    "php": { 
     "version": "5.4.9" 
    } 
} 

आप डिफ़ॉल्ट विशेषताओं का उपयोग करना चाहते हैं/.rb प्रारूप में कोई गुण, आप महाराज-सर्वर/महाराज ग्राहक उपयोग करने की आवश्यकता के लिए जा रहे हैं।

+0

यह वास्तव में अजीब है ... लेकिन मैं सिर्फ वीएम दूर विस्फोट से उड़ा दिया और यह पुनर्निर्माण किया। फिर ओपी में प्रदान की गई मेरी स्क्रिप्ट चलाई और यह ठीक काम किया। मुझे नहीं पता कि पहले वीएम के साथ क्या हुआ। –

+0

यह वास्तव में अजीब है: http://wiki.opscode.com/display/chef/Chef+Solo#ChefSolo-JSON%2CAttributesandRecipes –

5

डिफ़ॉल्ट गुण बावर्ची सोलो

मुझे यकीन है कि क्या अपने रसोई की किताब के अंदर क्या हो रहा है नहीं कर रहा हूँ में ठीक से काम - लेकिन यह अपने कोड के साथ एक मुद्दा है, बावर्ची के साथ नहीं। एक साधारण उदाहरण के रूप में, यह बाहर की जाँच:

https://gist.github.com/adamhjk/6141718

+0

आपका शेफ-एकल संस्करण क्या है? –

+0

मैं अपने लिए यह काम पुष्टि कर सकता हूं 'शेफ-एकल - संस्करण शेफ: 11.10.4' – devalias