Sha256: 36ebfed4e7d8fd55493999fc7f4d45d79d6e4466a2511df887c72c7ee41f8b41

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

require 'librarian/puppet'
require 'librarian/action'

module VagrantPlugins
  module LibrarianPuppet
    module Action
      class Install
        def initialize(app, env)
          @app = app
          @env = env
          # Config#finalize! SHOULD be called automatically
          env[:global_config].librarian_puppet.finalize!
        end

        def call(env)
          config = env[:global_config].librarian_puppet
          if
            provisioned? and
            File.exist? File.join(env[:root_path], config.puppetfile_path)

            env[:ui].info "Installing Puppet modules with Librarian-Puppet..."

            # NB: Librarian::Puppet::Environment calls `which puppet` so we
            # need to make sure VAGRANT_HOME/gems/bin has been added to the
            # path.
            original_path = ENV['PATH']
            bin_path = env[:gems_path].join('bin')
            ENV['PATH'] = "#{bin_path}#{::File::PATH_SEPARATOR}#{ENV['PATH']}"

            environment = Librarian::Puppet::Environment.new({
              :project_path => File.join(env[:root_path], config.puppetfile_dir)
            })
            Librarian::Action::Ensure.new(environment).run
            Librarian::Action::Resolve.new(environment).run
            Librarian::Action::Install.new(environment).run

            # Restore the original path
            ENV['PATH'] = original_path
          end
          @app.call(env)
        end

        def provisioned?
          @env[:provision_enabled].nil? ? true : @env[:provision_enabled]
        end

      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vagrant-librarian-puppet-plugin-0.1.3 lib/vagrant-librarian-puppet-plugin/action/librarian_puppet.rb