Sha256: ae4d96cb87cfcb0f232fcdbccf3ec4b64e7455c301f6b487c4e621c9936d2924

Contents?: true

Size: 1.94 KB

Versions: 21

Compression:

Stored size: 1.94 KB

Contents

require "log4r"

module Vagrant
  module Action
    module VM
      class Provision
        def initialize(app, env)
          @logger = Log4r::Logger.new("vagrant::action::vm::provision")
          @app = app

          env["provision.enabled"] = true if !env.has_key?("provision.enabled")
        end

        def call(env)
          @env = env

          provisioners = nil

          # We set this here so that even if this value is changed in the future,
          # it stays constant to what we expect here in this moment.
          enabled = env["provision.enabled"]
          if enabled
            # Instantiate and prepare the provisioners. Preparation must happen here
            # so that shared folders and such can properly take effect.
            provisioners = enabled_provisioners
            provisioners.map { |p| p.prepare }
          end

          @app.call(env)

          if enabled
            # Take prepared provisioners and run the provisioning
            provisioners.each do |instance|
              @env[:ui].info I18n.t("vagrant.actions.vm.provision.beginning",
                                    :provisioner => instance.class)
              instance.provision!
            end
          end
        end

        def enabled_provisioners
          enabled = []
          @env[:vm].config.vm.provisioners.each do |provisioner|
            if @env["provision.types"]
              # If we've specified types of provisioners to enable, then we
              # only use those provisioners, and skip any that we haven't
              # specified.
              if !@env["provision.types"].include?(provisioner.shortcut.to_s)
                @logger.debug("Skipping provisioner: #{provisioner.shortcut}")
                next
              end
            end

            enabled << provisioner.provisioner.new(@env, provisioner.config)
          end

          # Return the enable provisioners
          enabled
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
vagrantup-1.0.1 lib/vagrant/action/vm/provision.rb
vagrantup-1.0.0 lib/vagrant/action/vm/provision.rb
vagrantup-0.9.99.2 lib/vagrant/action/vm/provision.rb
vagrantup-0.9.99.1 lib/vagrant/action/vm/provision.rb
vagrantup-0.9.7 lib/vagrant/action/vm/provision.rb
vagrantup-0.9.6 lib/vagrant/action/vm/provision.rb
vagrantup-0.9.5 lib/vagrant/action/vm/provision.rb
vagrantup-0.9.4 lib/vagrant/action/vm/provision.rb
vagrantup-0.9.3 lib/vagrant/action/vm/provision.rb
vagrantup-0.9.2 lib/vagrant/action/vm/provision.rb
vagrantup-0.9.1 lib/vagrant/action/vm/provision.rb
vagrantup-0.9.0 lib/vagrant/action/vm/provision.rb
vagrant-1.0.1 lib/vagrant/action/vm/provision.rb
vagrant-1.0.0 lib/vagrant/action/vm/provision.rb
vagrant-0.9.7 lib/vagrant/action/vm/provision.rb
vagrant-0.9.5 lib/vagrant/action/vm/provision.rb
vagrant-0.9.4 lib/vagrant/action/vm/provision.rb
vagrant-0.9.3 lib/vagrant/action/vm/provision.rb
vagrant-0.9.2 lib/vagrant/action/vm/provision.rb
vagrant-0.9.1 lib/vagrant/action/vm/provision.rb