Class: Bolt::ModuleInstaller::Installer

Inherits:
Object
  • Object
show all
Defined in:
lib/bolt/module_installer/installer.rb

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Installer

Returns a new instance of Installer.



11
12
13
# File 'lib/bolt/module_installer/installer.rb', line 11

def initialize(config = {})
  @config = config
end

Instance Method Details

#install(path, moduledir) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/bolt/module_installer/installer.rb', line 15

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