Class: Bolt::ModuleInstaller::Resolver

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

Instance Method Summary collapse

Instance Method Details

#resolve(specs, config = {}) ⇒ Object

Resolves module specs and returns a Puppetfile object.


12
13
14
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/bolt/module_installer/resolver.rb', line 12

def resolve(specs, config = {})
  require 'puppetfile-resolver'

  # Build the document model from the specs.
  document   = PuppetfileResolver::Puppetfile::Document.new('')
  unresolved = []

  specs.specs.each do |spec|
    if spec.resolve
      document.add_module(spec.to_resolver_module)
    else
      unresolved << spec
    end
  end

  # Make sure the document model is valid.
  unless document.valid?
    message = <<~MESSAGE.chomp
      Unable to resolve module specifications:

      #{document.validation_errors.map(&:message).join("\n")}
    MESSAGE

    raise Bolt::Error.new(message, 'bolt/module-resolver-error')
  end

  # Create the resolver using the Puppetfile model. nil disables Puppet
  # version restrictions.
  resolver = PuppetfileResolver::Resolver.new(document, nil)

  # Configure and resolve the dependency graph, catching any errors
  # raised by puppetfile-resolver and re-raising them as Bolt errors.
  begin
    result = resolver.resolve(
      cache:                       nil,
      ui:                          nil,
      allow_missing_modules:       false,
      spec_searcher_configuration: spec_searcher_config(config)
    )
  rescue StandardError => e
    raise Bolt::Error.new(e.message, 'bolt/module-resolver-error')
  end

  # Create the Puppetfile object.
  generate_puppetfile(specs, result.specifications.values, unresolved)
end