2014-01-22 23 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 –