2014-01-22 22 views
25

我試圖使用Chef來安裝石墨服務器,並且遇到錯誤,指出在VM上未找到chef-solo或chef-client。我使用Ubuntu 12.04.amd64 LTS,這是服務器版本,所以它不會安裝chef-client。我知道13版本會自動安裝廚師客戶端,但我不能使用13版本。Vagrant在基本映像之上安裝chef-client

我GOOGLE了一下,看到一些人建議ssh到框和apt-get安裝廚師客戶端。

我的問題是:無論如何,我可以預先安裝廚師客戶之前廚師踢?基本上我想我的廚師程序下載原始圖像,並且不需要用戶額外的手動步驟就可以完成所有操作。可能嗎?

我Vagrantfile:

Vagrant.configure("2") do |config| 
    config.vm.box = "ubuntu-12.04-amd64" 
    config.vm.box_url = "http://cloud-images.ubuntu.com/vagrant/precise/current/precise-server-cloudimg-amd64-vagrant-disk1.box" 
    config.vm.hostname = "graphite" 
    config.vm.network :forwarded_port, guest: 8080, host: 9090 

    config.vm.provision :chef_solo do |chef| 
     chef.cookbooks_path = "cookbooks" 
     chef.roles_path = "roles" 
     chef.data_bags_path = "data_bags" 
     chef.add_role "Graphite-Server" 
     chef.add_role "StatsD-Server" 
    end 
end 

錯誤日誌:

[default] Running provisioner: chef_solo... 
The chef binary (either `chef-solo` or `chef-client`) was not found on 
the VM and is required for chef provisioning. Please verify that chef 
is installed and that the binary is available on the PATH. 

感謝

+0

我在這裏找到了一些解決方案:https://github.com/mitchellh/vagrant-aws/issues/19 –

+0

這取決於您的基盒,如果廚師是預裝的。我非常肯定,Ubuntu 13. *有廚師*預安裝*,只能通過'apt'使用。 – StephenKing

+0

對不起,我的意思是「也是Ubuntu 13. *有廚師**不是** *預安裝*」 – StephenKing

回答

40

我發現2個解決方案和預期都工作:

1)方法1: 在你Vagrantfile,添加

config.omnibus.chef_version = :latest

這將確保無論廚師獨奏廚師客戶端安裝在VM上,並且是廚師提供所需的。爲了使用綜合性的插件,請務必先安裝插件:vagrant plugin install vagrant-omnibus

2)方法2:使用config.vm.provision外殼內嵌這裏提到:https://github.com/mitchellh/vagrant-aws/issues/19#issuecomment-15487131。在你Vagrantfile,添加:

config.vm.provision "shell", path: "utils/tools/install_chef.bash"

腳本utils的/工具/ install_chef.bash,我寫這個樣子的:

#!/bin/bash 

function error 
{ 
    echo -e "\033[1;31m${1}\033[0m" 1>&2 
} 

function checkRequireRootUser 
{ 
    if [[ "$(whoami)" != 'root' ]] 
    then 
     error "ERROR: please run this program as 'root'" 
     exit 1 
    fi 
} 

function installChef() 
{ 
    if [[ "$(which chef-client)" = '' ]] 
    then 
     local chefProfilePath='/etc/profile.d/chef.sh' 

     curl -s -L 'https://www.opscode.com/chef/install.sh' | bash && \ 
     echo 'export PATH="/opt/chef/embedded/bin:$PATH"' > "${chefProfilePath}" && \ 
     source "${chefProfilePath}" 
    fi 
} 

function main() 
{ 
    checkRequireRootUser 
    installChef 
} 

main 

UPDATE:

,如果你得到以下錯誤:Unknown configuration section 'omnibus'。這意味着你錯過了omnibus插件。要安裝它,請輸入:vagrant plugin install vagrant-omnibus

+1

當然,這也沒關係。我之前也有類似的東西。如果你的網絡連接速度很慢,你可以把'。deb'文件,在那裏它可以通過同步文件夾(在目錄下,你的'Vagrantfile'所在的位置或使用額外的共享位置)獲得。然後,你可以只用'dpkg -i chef * .deb'來安裝廚師,而無需一遍又一遍地下載。 – StephenKing

+0

呵呵......絕妙的主意。這可能是第三種如何解決問題的方法。我會試試看!謝謝@StephenKing –