Sha256: dedc14b3e549f92b2dc326b1c9dd7f261c4f08fc37a1df19bdded074bbe07e9f

Contents?: true

Size: 1.12 KB

Versions: 8

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

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 ModuleInstaller
    class Installer
      def initialize(config = {})
        @config = config
      end

      def install(path, moduledir)
        require 'r10k/cli'

        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

8 entries across 8 versions & 1 rubygems

Version Path
bolt-3.17.0 lib/bolt/module_installer/installer.rb
bolt-3.16.1 lib/bolt/module_installer/installer.rb
bolt-3.16.0 lib/bolt/module_installer/installer.rb
bolt-3.15.0 lib/bolt/module_installer/installer.rb
bolt-3.14.1 lib/bolt/module_installer/installer.rb
bolt-3.13.0 lib/bolt/module_installer/installer.rb
bolt-3.12.0 lib/bolt/module_installer/installer.rb
bolt-3.11.0 lib/bolt/module_installer/installer.rb