lib/bolt/cli.rb
# Resolves Puppetfile specs from user-specified modules and dependencies resolved
# by the puppetfile-resolver gem.
Resolves Puppetfile specs from user-specified modules and dependencies resolved
by the puppetfile-resolver gem.
Resolves Puppetfile specs from user - specified modules and dependencies resolved by the puppetfile - resolver gem .
def resolve_puppetfile_specs
      require 'puppetfile-resolver'
      model = PuppetfileResolver::Puppetfile::Document.new('')
      options[:modules].each do |mod_name|
        model.add_module(
          PuppetfileResolver::Puppetfile::ForgeModule.new(mod_name).tap { |mod| mod.version = :latest }
        )
      end
      unless model.valid?
        raise Bolt::ValidationError,
              "Unable to resolve dependencies for #{options[:modules].join(', ')}"
      end
      resolver = PuppetfileResolver::Resolver.new(model, nil)
      result = resolver.resolve(
        cache:                 nil,
        ui:                    nil,
        module_paths:          [],
        allow_missing_modules: true
      )
      missing_graph = result.specifications.select do |_name, spec|
        spec.instance_of? PuppetfileResolver::Models::MissingModuleSpecification
      end
      if missing_graph.any?
        titles = model.modules.each_with_object({}) do |mod, acc|
          acc[mod.name] = mod.title
        end
        names = titles.values_at(*missing_graph.keys)
        plural = names.count == 1 ? '' : 's'
        raise Bolt::ValidationError,
              "Unknown module name#{plural} #{names.join(', ')}"
      end
      spec_graph = result.specifications.select do |_name, spec|
        spec.instance_of? PuppetfileResolver::Models::ModuleSpecification
      end
      spec_graph.values.map do |spec|
        "mod '#{spec.owner}-#{spec.name}', '#{spec.version}'"
      end
    end
def resolve_puppetfile_specs require 'puppetfile-resolver' model = PuppetfileResolver :: Puppetfile :: Document . new ( '' ) options [ :modules ] . each do | mod_name | model . add_module ( PuppetfileResolver :: Puppetfile :: ForgeModule . new ( mod_name ) . tap { | mod | mod . version = :latest } ) end unless model . valid? raise Bolt :: ValidationError , "Unable to resolve dependencies for #{options[:modules].join(', ')}" end resolver = PuppetfileResolver :: Resolver . new ( model , nil ) result = resolver . resolve ( cache : nil , ui : nil , module_paths : [ ] , allow_missing_modules : true ) missing_graph = result . specifications . select do | _name , spec | spec . instance_of? PuppetfileResolver :: Models :: MissingModuleSpecification end if missing_graph . any? titles = model . modules . each_with_object ( { } ) do | mod , acc | acc [ mod . name ] = mod . title end names = titles . values_at ( * missing_graph . keys ) plural = names . count == 1 ? '' : 's' raise Bolt :: ValidationError , "Unknown module name#{plural} #{names.join(', ')}" end spec_graph = result . specifications . select do | _name , spec | spec . instance_of? PuppetfileResolver :: Models :: ModuleSpecification end spec_graph . values . map do | spec | "mod '#{spec.owner}-#{spec.name}', '#{spec.version}'" end end
Resolves Puppetfile specs from user-specified modules and dependencies resolved
by the puppetfile-resolver gem.
Resolves Puppetfile specs from user - specified modules and dependencies resolved by the puppetfile - resolver gem .
# Build the document model from the module names, defaulting to the latest version of each module # Make sure the Puppetfile model is valid # Create the resolver using the Puppetfile model. nil disables Puppet version restrictions. # Configure and resolve the dependency graph # Validate that the modules exist # Filter the dependency graph to only include module specifications # Map specification models to a Puppetfile specification