在Vagrant多机设置中能否获得供应商的由内而外的订购? [英] Is it possible to get inside-out ordering of provisioners in a Vagrant multi-machine setup?

查看:64
本文介绍了在Vagrant多机设置中能否获得供应商的由内而外的订购?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用多计算机设置时,是否可以将预配器的顺序从最内到最外?我希望一个小的Shell配置程序在使用puppet进行配置之前在/etc/facter/facts.d/中创建一些事实,以尽可能地模仿我们当前的设置. (我继承了一个大型的木偶仓库,并试图在开始进行更改之前为其创建一个Vagrant测试平台.)

Is it possible to reverse the order of provisioners from innermost to outermost when using a multi-machine setup? I want a small shell provisioner to create some facts in /etc/facter/facts.d/ before provisioning with puppet, to mimic our current setup as much as possible. (I have inherited a large puppet repo and am trying to create a Vagrant testbed for it before I start doing changes.)

每个框的人偶设置都相同,但是要求shell配置程序首先运行.这是一个Vagrantfile示例,以显示我想做的事(更改了一些名称以保护无辜者):

The puppet settings are the same for every box, but requires the shell provisioner to run first. Here's an example Vagrantfile to show what I want to do (some names changed to protect the innocent):

$facts =<<FACTS
set -x
mkdir -p /etc/facter/facts.d
echo role=$1        > /etc/facter/facts.d/role.txt
echo location=$2    > /etc/facter/facts.d/location.txt
echo environment=$3 > /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

推荐答案

当我找到一个可接受的解决方法时,回答我自己的问题:我将人偶调配移动到内部块中.这是我当前的代码:

Answering my own question as I found an acceptable workaround: I moved the puppet provisioning into the inner block. Here's what my current code looks like:

$facts =<<SET_FACTS
set -x
mkdir -p /etc/facter/facts.d
echo role=$1        > /etc/facter/facts.d/role.txt
echo location=$2    > /etc/facter/facts.d/location.txt
echo environment=$3 > /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

这篇关于在Vagrant多机设置中能否获得供应商的由内而外的订购?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆