是否有可能在 Vagrant 多机设置中获得供应商的由内而外的排序?

Is it possible to get inside-out ordering of provisioners in a Vagrant multi-machine setup?

在使用多机设置时,是否可以将供应商的顺序从最内到最外颠倒过来?我想要一个小型 shell 提供者在使用 puppet 提供之前在 /etc/facter/facts.d/ 中创建一些事实,以尽可能地模仿我们当前的设置。 (我继承了一个大型 puppet 存储库,并在开始进行更改之前尝试为其创建一个 Vagrant 测试平台。)

每个盒子的木偶设置都相同,但需要 shell 供应商先 运行。这是一个示例 Vagrantfile 来展示我想做的事情(为了保护无辜者更改了一些名称):

$facts =<<FACTS
set -x
mkdir -p /etc/facter/facts.d
echo role=        > /etc/facter/facts.d/role.txt
echo location=    > /etc/facter/facts.d/location.txt
echo environment= > /etc/facter/facts.d/environment.txt
FACTS

Vagrant.configure(2) do |config|
  config.vm.box = "centos-6.6"
  config.vm.synced_folder "hiera", "/etc/puppet/hiera"

  config.vm.provision :puppet do |puppet|
    puppet.manifest_file = "site.pp"
    puppet.module_path = ["modules", "internal"]
    puppet.hiera_config_path = "hiera.yaml"
    puppet.options = "--test"
  end

  config.vm.define :foo1 do |c|
    c.vm.hostname = "foo-1.vagrant"
    c.vm.provision :shell, inline: $facts, args: "foo testing stage"
  end

  config.vm.define :bar do |c|
    c.vm.hostname = "bar-1.vagrant"
    c.vm.provision :shell, inline: $facts, args: "bar testing stage"
  end

  # ... more machines omitted ...

end

回答我自己的问题,因为我找到了一个可接受的解决方法:我将 puppet 配置移到了内部块中。这是我当前的代码:

$facts =<<SET_FACTS
set -x
mkdir -p /etc/facter/facts.d
echo role=        > /etc/facter/facts.d/role.txt
echo location=    > /etc/facter/facts.d/location.txt
echo environment= > /etc/facter/facts.d/environment.txt
SET_FACTS

module Vagrant
  module Config
    module V2
      class Root
        def provision(role, location, environment)
          vm.provision "set-facts",
                         type: :shell,
                         inline: $facts,
                         args: [role, location, environment].map { |x| x.to_s }
          vm.provision :puppet do |puppet|
            puppet.manifest_file = "site.pp"
            puppet.module_path = ["modules", "internal"]
            puppet.hiera_config_path = "hiera.yaml"
          end
        end
      end
    end
  end
end

Vagrant.configure(2) do |config|
  config.vm.box = "centos-6.6"
  config.vm.synced_folder "hiera", "/etc/puppet/hiera"

  config.vm.define :foo1 do |c|
    c.vm.hostname = "foo-1.vagrant"
    c.provision(:foo, :testing, :stage)
  end

  config.vm.define :bar1 do |c|
    c.vm.hostname = "bar-1.vagrant"
    c.provision(:bar, :testing, :stage)
  end
end