Manage multiple cars.

I have a multi-machine roaming setup with some blocks that I need to change for the execution order.

Due to the fact that the firewall is external, the latter is executed in the nested block itself.

I need a way to make selection locks more nested so that they are executed last. I tried adding mach.vm.define, but these blocks are not executing, and I don't understand why.

Normal execution, wrong order

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 

Ideal solution, but an additional nested block does not execute

 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 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 

Is there a way to make the training level one level deeper so that it works after the contents of the vendor block?

EDIT: anything that is specific to the provider is unacceptable (like another provider block) or anything that causes duplicate code.

+5
source share
1 answer

I don’t know what exactly you are doing in the first block, so I assume that it can be inverted using the internal block (the one that interacts with the attribute :run_this ).

With this small change, we can put all the execution blocks on the same level. Below you will find the code that I tried to simulate your problem.

 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 end 
+1
source

All Articles