【问题标题】:Vagrant Install chef-client on top of base imageVagrant 在基础镜像之上安装 chef-client
【发布时间】:2014-02-12 00:13:57
【问题描述】:

我正在尝试使用 Chef 安装石墨服务器,但遇到错误,提示在 VM 上找不到 chef-solo 或 chef-client。我使用的是 Ubuntu 12.04.amd64 LTS,这是服务器版本,所以它不会安装 chef-client。我知道 13 版本会自动安装 chef-client 但我不能使用 13 版本。

我用谷歌搜索,看到有人建议通过 ssh 连接到盒子并 apt-get install chef-client。

我的问题是:无论如何,我可以在 chef 开始之前预安装 chef-client 吗?基本上我希望我的厨师程序下载原始图像并在没有用户额外手动步骤的情况下完成所有操作。有可能吗?

我的流浪文件:

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.

谢谢

【问题讨论】:

  • 我在这里找到了一些解决方案:github.com/mitchellh/vagrant-aws/issues/19
  • 这取决于你的基本盒子,如果厨师是预装的。我很确定 Ubuntu 13.* 也有 Chef preeinstalled,只能通过 apt 获得。
  • 对不起,我的意思是“Ubuntu 13.* 也有主厨 not preeinstalled

标签: chef-infra vagrant


【解决方案1】:

我找到了 2 个解决方案,并且都按预期工作:

1) 方法一: 在你的 Vagrantfile 中,添加

config.omnibus.chef_version = :latest

这将确保 chef-solochef-client 已安装在 VM 上,并且是厨师配置所必需的。为了使用omnibus插件,请确保先安装插件:vagrant plugin install vagrant-omnibus

2) 方法 2: 使用 config.vm.provision shell 内联,如此处所述:https://github.com/mitchellh/vagrant-aws/issues/19#issuecomment-15487131。在您的 Vagrantfile 中,添加:

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

我写的脚本utils/tools/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

更新:

如果您收到以下错误:Unknown configuration section 'omnibus'。这意味着您缺少综合插件。要安装它,请输入:vagrant plugin install vagrant-omnibus

【讨论】:

  • 当然,没关系。我以前也有类似的东西。如果您的 Internet 连接速度较慢,您可以将 .deb 文件放在某个位置,该文​​件可通过同步文件夹访问(在您的 Vagrantfile 所在的目录下方或使用附加共享)。然后你就可以dpkg -i chef*.deb安装chef,不需要一遍又一遍的下载。
  • 嗯……好主意。这可能是解决问题的第三种方法。我会试试看!谢谢@StephenKing
【解决方案2】:

如果没有安装chef,我可以推荐vagrant-omnibus 插件,它基本上会为你执行install.sh 脚本。

【讨论】:

  • 或者只是使用测试厨房:)
猜你喜欢
  • 1970-01-01
  • 2019-04-03
  • 1970-01-01
  • 1970-01-01
  • 2015-10-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-14
相关资源
最近更新 更多