gpt4 book ai didi

vagrant - 如何在 Vagrant 中为多机环境指定配置器默认值?

转载 作者:行者123 更新时间:2023-12-04 12:54:13 26 4
gpt4 key购买 nike

我想知道在使用 Vagrant 创建多机环境时是否有办法为供应商指定默认值?

我试图做如下事情:

Vagrant.configure("2") do |config|
config.vm.box = "andyshinn/ubuntu-precise64"

config.vm.provision :chef_client do |chef|
chef.chef_server_url = "https://api.opscode.com/organizations/myorg"
chef.validation_key_path = "~/.chef/myorg-validator.pem"
chef.delete_node = true
chef.delete_client = true
chef.validation_client_name = "myorg-validator"
end

config.vm.define :app do |app|
app.vm.network "private_network", ip: "172.16.64.61"
app.vm.host_name = "vagrant-app-#{ENV['USER']}"

app.vm.provision :chef_client do |chef|
chef.add_recipe "myrecipe1"
chef.add_recipe "myrecipe2"
chef.add_recipe "sudo"
end
end

config.vm.define :web do |web|
web.vm.network "private_network", ip: "172.16.64.62"
web.vm.host_name = "vagrant-web-#{ENV['USER']}"

web.vm.provision :chef_client do |chef|
chef.add_recipe "myrecipe3"
chef.add_recipe "myrecipe4"
chef.add_recipe "sudo"
end
end
end

但是每个 VM 块似乎都没有选择任何主要的配置块设置。我收到此错误:
There are errors in the configuration of this machine. Please fix
the following errors and try again:

chef client provisioner:
* Chef server URL must be populated.
* Validation key path must be valid path to your chef server validation key.

可以通过另一种方法吗?

最佳答案

您的问题是范围之一。变量 chefconfig.vm.provision 中具有块作用域做块。

一旦此块退出,您的更改就会消失。您应该遵循 multi-machine 中的示例vagrant 网站上的文档。
config.vm.provision "shell", inline: "echo Hello"

Vagrant.configure("2") do |config|
config.vm.box = "andyshinn/ubuntu-precise64"


config.vm.provision "chef_client", chef_server_url: "https://api.opscode.com/organizations/myorg"
config.vm.provision "chef_client", validation_key_path: "~/.chef/myorg-validator.pem
config.vm.provision "chef_client", delete_node: true
config.vm.provision "chef_client", delete_client: true
config.vm.provision "chef_client", validation_client_name: "myorg-validator"


config.vm.define :app do |app|
app.vm.network "private_network", ip: "172.16.64.61"
app.vm.host_name = "vagrant-app-#{ENV['USER']}"

app.vm.provision :chef_client do |chef|
chef.add_recipe "myrecipe1"
chef.add_recipe "myrecipe2"
chef.add_recipe "sudo"
end
end

应该做的伎俩

关于vagrant - 如何在 Vagrant 中为多机环境指定配置器默认值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22569223/

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