Vagrant Box在Knife Cookbook安装后崩溃

6
我是一个 Vagrant 初学者,正在使用 chef-solo 设置一个相当简单的 CentOS LAMP 盒子,但无法使 Vagrant 和 Chef 的 knife 命令协同工作。
以下是问题的简要说明:
我使用vagrantbox.es上的基于CentOS 6.3 w/ Chef基础盒子创建了一个基本的Vagrantfile。你可以在this gist中看到基本信息。 我通过knife cookbook site install nameofcookbook下载了所有的cookbook,并使用配置将它们放在./chef/cookbooks中。 我成功地运行了vagrant up,你可以在this gist中看到基本信息。 我测试了apache、php等,一切正常。 现在来关键的部分:在虚拟机运行时,我使用knife添加了另一个软件包(在这种情况下是i3)。 从这里开始,Vagrant无法在虚拟机中执行各种任务: 当我运行vagrant provision时,会出现以下错误:
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.
当我运行vagrant halt时,出现一个错误,提示ssh命令以非零错误代码退出。
然而,我可以运行vagrant ssh,并确认(a)在虚拟机中确实存在chef-solo,(b)我可以通过命令行关闭虚拟机。
  • When I run vagrant up I get an error like this:
    The following SSH command responded with a non-zero exit status.
    Vagrant assumes that this means the command failed!
    mkdir -p /vagrant</li>
    

    I'm stumped. I've had this happen on two boxes already, and I know that Knife and Vagrant should be able to play well together.

    What am I doing wrong?

    Any help much appreciated, I've very excited about digging into Vagrant!

  • 1个回答

    17
    chef.add_recipe "sudo"
    

    第一次运行后删除了你的sudo文件。

    在你的vagrant文件中为你的vagrant用户添加适当的json。

    类似于:

    config.vm.provision :chef_solo do |chef|
    
      # add your recipes
      # chef.add_recipe "foo"
      # chef.add_role   "bar"
      chef.json = {
        "authorization" => {
            "sudo" => {
                "users" => [ "vagrant" ],
                "passwordless" => true,
            }
        }
      }
    end
    

    1
    我不理解“第一次运行后删除了您的sudo文件”的意思。 - Dzung Nguyen
    @Vdt 厨师更新了sudo配方,删除了“vagrant”用户的sudo权限。除非按照上面所示添加该用户,否则您将无法再次运行厨师,因为它需要sudo权限。 - EnabrenTane
    在虚拟机中根本找不到chef-solo或chef-client,这似乎不像是你安装的json中有chef-solo/chef-client。 - holms
    @holms 是的,你的虚拟机需要安装 Chef 才能使上述工作正常运行。 - EnabrenTane
    我在我的Vagrant文件中使用了config.omnibus.chef_version = :latest,并在vagrant plugin install vagrant-omnibus之前安装了vagrant插件。 - holms
    我在使用这种方法之前实际上尝试了一些其他的东西,请参见(下面的链接)。这绝对是我找到的最干净的解决方案。 资源: 可能的解决方法通过菜谱,但对我不起作用sudo菜谱如何将chef锁定在系统外的更好解释 - Chip

    网页内容由stack overflow 提供, 点击上面的
    可以查看英文原文,
    原文链接