我有一个多机流浪设置与一些块,我需要改变执行顺序。
由于流浪顺序在外部-内部,所以嵌套最多的块最后执行。
我需要一种方法来使预置块更嵌套,以便它们最后执行。我尝试添加mach.vm.define,但是这些块不能执行,我不明白为什么。
执行正常,顺序错误
Vagrant.require_version ">= 1.6.0"
VAGRANTFILE_API_VERSION = "2"
require 'yaml'
machines = YAML.load_file('vagrant.yaml')
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
machines.each do |machine|
config.vm.define machine["name"] do |mach|
machine['run_this'].each do |run_this|
mach.vm.provider "virtualbox" do |v, override|
# should run first
end
end
# Do a puppet provision to install the rest of the software
mach.vm.provision "puppet" do |puppet|
# puppet stuff
end
mach.vm.box = 'ubuntu/trusty64'
end
end理想的解决方案,但额外的嵌套块不会执行
Vagrant.require_version ">= 1.6.0"
VAGRANTFILE_API_VERSION = "2"
require 'yaml'
machines = YAML.load_file('vagrant.yaml')
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
machines.each do |machine|
config.vm.define machine["name"] do |mach|
machine['run_this'].each do |run_this|
mach.vm.provider "virtualbox" do |v, override|
# should run first but it doesn't because it's in an extra provider block
end
end
mach.vm.define :prov do |prov| # This block doesn't execute
# Do a puppet provision to install the rest of the software
prov.vm.provision "puppet" do |puppet|
# puppet stuff
end
end
mach.vm.box = 'ubuntu/trusty64'
end
end
end有没有办法让供应更深一层,这样它就会在提供者区块的内容之后运行?
编辑:任何特定于提供程序的内容都是不可接受的(例如,另一个提供程序块),或者任何会导致重复代码的内容。
发布于 2015-08-31 23:40:43
我不知道您在第一个块上到底做了什么,所以我假设它可以与内部块(与:run_this属性交互的块)颠倒。
有了这个小小的改变,我们就可以将所有的执行块放在同一个级别上。下面你会找到我试图模拟你的问题的代码。
Vagrant.require_version ">= 1.6.0"
VAGRANTFILE_API_VERSION = "2"
require "yaml"
machines = YAML.load_file("vagrant.yml")
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
machines.each do |machine|
config.vm.define machine["name"] do |mach|
mach.vm.box = "ubuntu/trusty64"
mach.vm.provision :shell, inline: "echo A"
mach.vm.provider :virtualbox do |v, override|
v.name = machine["name"]
override.vm.provision :shell, inline: "echo B"
machine["run_this"].each do |run_this|
override.vm.provision :shell, inline: "echo C"
end
# puppet stuff should come here (all on the same level)
override.vm.provision :shell, inline: "echo D"
end
end
end
endhttps://stackoverflow.com/questions/32203536
复制相似问题