Method: Bolt::PAL#lookup

Defined in:
lib/bolt/pal.rb

#lookup(key, targets, inventory, executor, _concurrency) ⇒ Object



619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
# File 'lib/bolt/pal.rb', line 619

def lookup(key, targets, inventory, executor, _concurrency)
  # Install the puppet-agent package and collect facts. Facts are
  # automatically added to the targets.
  in_plan_compiler(executor, inventory, nil) do |compiler|
    compiler.call_function('apply_prep', targets)
  end

  overrides = {
    bolt_inventory: inventory,
    bolt_project:   @project
  }

  # Do a lookup with a catalog compiler, which uses the 'hierarchy' key in
  # Hiera config.
  results = targets.map do |target|
    node = Puppet::Node.from_data_hash(
      'name'       => target.name,
      'parameters' => { 'clientcert' => target.name }
    )

    trusted = Puppet::Context::TrustedInformation.local(node).to_h

    env_conf = {
      modulepath: @modulepath.full_modulepath,
      facts:      target.facts,
      variables:  target.vars
    }

    with_puppet_settings do
      Puppet::Pal.in_tmp_environment(target.name, **env_conf) do |pal|
        Puppet.override(overrides) do
          Puppet.lookup(:pal_current_node).trusted_data = trusted
          pal.with_catalog_compiler do |compiler|
            Bolt::Result.for_lookup(target, key, compiler.call_function('lookup', key))
          rescue StandardError => e
            Bolt::Result.from_exception(target, e)
          end
        end
      end
    end
  end

  Bolt::ResultSet.new(results)
end