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

33 views
Skip to first unread message

sbrau...@gmail.com

unread,
Sep 16, 2015, 10:19:44 AM9/16/15
to Vagrant
Hi! I'm new here.

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

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 foo_role=$1        > /etc/facter/facts.d/role.txt
echo foo_location=$2    > /etc/facter/facts.d/location.txt
echo foo_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

If that's not possible, is there a way to "macroify" the puppet setup so I can add it as a single line to each defined machine? (I am not not familiar with the terminology in Ruby nor Vagrant.) Any other suggestions welcome.

Stig

sbrau...@gmail.com

unread,
Sep 16, 2015, 11:49:00 AM9/16/15
to Vagrant
A work-around would be to just run `vagrant up --provision-with shell`, then `vagrant provision --provision-with puppet` but that feels a bit clunky.

Stig

sbrau...@gmail.com

unread,
Sep 18, 2015, 12:12:32 PM9/18/15
to Vagrant
I found an acceptable workaround:

$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



On Wednesday, 16 September 2015 15:19:44 UTC+1, sbrau...@gmail.com wrote:
Reply all
Reply to author
Forward
0 new messages