gpt4 book ai didi

chef-infra - Vagrant 在基础镜像上安装 Chef-client

转载 作者:行者123 更新时间:2023-12-03 10:35:58 26 4
gpt4 key购买 nike

我正在尝试使用 Chef 安装 Graphite 服务器,但遇到错误,提示在 VM 上找不到 Chef-solo 或 Chef-client。我使用的是 Ubuntu 12.04.amd64 LTS,这是服务器版本,因此不会安装 Chef-client。我知道 13 版本会自动安装厨师客户端,但我不能使用 13 版本。

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

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

我的 Vagrant 文件:

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.

谢谢

最佳答案

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

1) 方法一:
在您的 Vagrantfile 中,添加
config.omnibus.chef_version = :latest
这将确保 厨师独奏厨师客户安装在 VM 上,是 Chef 配置所必需的。要使用综合插件,请确保先安装插件:vagrant plugin install vagrant-omnibus
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"
脚本实用程序/工具/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

关于chef-infra - Vagrant 在基础镜像上安装 Chef-client,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21274437/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com