Sha256: 1b165f0e4119f68fbfee70e3f1d771d9203bfde18cecc623958d643c20865545

Contents?: true

Size: 1.11 KB

Versions: 5

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

require 'r10k/cli'
require 'bolt/r10k_log_proxy'
require 'bolt/error'

# This class is used to install modules from a Puppetfile to a module directory.
#
module Bolt
  class Puppetfile
    class Installer
      def initialize(config = {})
        @config = config
      end

      def install(path, moduledir)
        unless File.exist?(path)
          raise Bolt::FileError.new(
            "Could not find a Puppetfile at #{path}",
            path
          )
        end

        r10k_opts = {
          root:       File.dirname(path),
          puppetfile: path.to_s,
          moduledir:  moduledir.to_s
        }

        settings = R10K::Settings.global_settings.evaluate(@config)
        R10K::Initializers::GlobalInitializer.new(settings).call
        install_action = R10K::Action::Puppetfile::Install.new(r10k_opts, nil)

        # Override the r10k logger with a proxy to our own logger
        R10K::Logging.instance_variable_set(:@outputter, Bolt::R10KLogProxy.new)

        install_action.call
      rescue R10K::Error => e
        raise PuppetfileError, e
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
bolt-2.31.0 lib/bolt/puppetfile/installer.rb
bolt-2.30.0 lib/bolt/puppetfile/installer.rb
bolt-2.29.0 lib/bolt/puppetfile/installer.rb
bolt-2.28.0 lib/bolt/puppetfile/installer.rb
bolt-2.27.0 lib/bolt/puppetfile/installer.rb