gpt4 book ai didi

ruby - 尝试循环创建机器时 Vagrant 堆栈级别太深(SystemStackError)

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:37:29 26 4
gpt4 key购买 nike

所以我正在尝试创建 vagrantfile 循环并为学校项目创建多台机器。

代码是:

def slave()
slave{i}
end

Vagrant.configure(2) do |config|
config.vm.box = "minimal/xenial64"
config.vm.provision "shell", inline: $ttscript

(1..3).each do |i|
config.vm.define "slave{i}" do |slave|
slave{i}.vm.hostname = "slave{i}"
end
end

结束

我无法将变量 i 放到从站现在所在的位置,所以我尝试为它创建定义,但它只是错误消息:

/home/mestari420/Vagrantfile:14:in `slave': stack level too deep (SystemStackError)
from /home/mestari420/Vagrantfile:14:in `slave'
from /home/mestari420/Vagrantfile:14:in `slave'
from /home/mestari420/Vagrantfile:14:in `slave'
from /home/mestari420/Vagrantfile:14:in `slave'
from /home/mestari420/Vagrantfile:14:in `slave'
from /home/mestari420/Vagrantfile:14:in `slave'
from /home/mestari420/Vagrantfile:14:in `slave'
from /home/mestari420/Vagrantfile:14:in `slave'
... 11894 levels...
from /usr/share/vagrant/plugins/commands/up/command.rb:85:in `execute'
from /usr/lib/ruby/vendor_ruby/vagrant/cli.rb:42:in `execute'
from /usr/lib/ruby/vendor_ruby/vagrant/environment.rb:268:in `cli'
from /usr/bin/vagrant:173:in `<main>'

我这样做的方法有什么问题吗?

最佳答案

主要问题是

slave{i}.vm.hostname

替换为

slave.vm.hostname

as slave 是那里使用的变量名。

关于ruby - 尝试循环创建机器时 Vagrant 堆栈级别太深(SystemStackError),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47169167/

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