lib/bolt/pal.rb
# Runs a block in a PAL script compiler configured for Bolt.  Catches
# exceptions thrown by the block and re-raises them ensuring they are
# Bolt::Errors since the script compiler block will squash all exceptions.
Runs a block in a PAL script compiler configured for Bolt.  Catches
exceptions thrown by the block and re-raises them ensuring they are
Bolt::Errors since the script compiler block will squash all exceptions.
Runs a block in a PAL script compiler configured for Bolt . Catches exceptions thrown by the block and re - raises them ensuring they are Bolt :: Errors since the script compiler block will squash all exceptions .
def in_bolt_compiler(compiler_params: {})
      setup
      compiler_params = compiler_params.merge(set_local_facts: false)
      r = Puppet::Pal.in_tmp_environment('bolt', modulepath: full_modulepath, facts: {}) do |pal|
        Puppet.override(bolt_project: @project,
                        yaml_plan_instantiator: Bolt::PAL::YamlPlan::Loader) do
          detect_project_conflict(@project, Puppet.lookup(:environments).get('bolt'))
          pal.with_script_compiler(**compiler_params) do |compiler|
            alias_types(compiler)
            register_resource_types(Puppet.lookup(:loaders)) if @resource_types
            begin
              yield compiler
            rescue Bolt::Error => e
              e
            rescue Puppet::DataBinding::LookupError => e
              if e.issue_code == :HIERA_UNDEFINED_VARIABLE
                message = "Interpolations are not supported in lookups outside of an apply block: #{e.message}"
                PALError.new(message)
              else
                PALError.from_preformatted_error(e)
              end
            rescue Puppet::PreformattedError => e
              if e.issue_code == :UNKNOWN_VARIABLE &&
                 %w[facts trusted server_facts settings].include?(e.arguments[:name])
                message = "Evaluation Error: Variable '#{e.arguments[:name]}' is not available in the current scope "\
                          "unless explicitly defined."
                details = { file: e.file, line: e.line, column: e.pos }
                PALError.new(message, details)
              else
                PALError.from_preformatted_error(e)
              end
            rescue StandardError => e
              PALError.from_preformatted_error(e)
            end
          end
        end
      end
      if r.is_a?(StandardError) && !r.is_a?(Bolt::PuppetError)
        raise r
      end
      r
    end
def in_bolt_compiler ( compiler_params : { } ) setup compiler_params = compiler_params . merge ( set_local_facts : false ) r = Puppet :: Pal . in_tmp_environment ( 'bolt' , modulepath : full_modulepath , facts : { } ) do | pal | Puppet . override ( bolt_project : @project , yaml_plan_instantiator : Bolt :: PAL :: YamlPlan :: Loader ) do detect_project_conflict ( @project , Puppet . lookup ( :environments ) . get ( 'bolt' ) ) pal . with_script_compiler ( ** compiler_params ) do | compiler | alias_types ( compiler ) register_resource_types ( Puppet . lookup ( :loaders ) ) if @resource_types begin yield compiler rescue Bolt :: Error => e e rescue Puppet :: DataBinding :: LookupError => e if e . issue_code == :HIERA_UNDEFINED_VARIABLE message = "Interpolations are not supported in lookups outside of an apply block: #{e.message}" PALError . new ( message ) else PALError . from_preformatted_error ( e ) end rescue Puppet :: PreformattedError => e if e . issue_code == :UNKNOWN_VARIABLE && %w[ facts trusted server_facts settings ] . include? ( e . arguments [ :name ] ) message = "Evaluation Error: Variable '#{e.arguments[:name]}' is not available in the current scope " "unless explicitly defined." details = { file : e . file , line : e . line , column : e . pos } PALError . new ( message , details ) else PALError . from_preformatted_error ( e ) end rescue StandardError => e PALError . from_preformatted_error ( e ) end end end end if r . is_a? ( StandardError ) && ! r . is_a? ( Bolt :: PuppetError ) raise r end r end
Runs a block in a PAL script compiler configured for Bolt.
Runs a block in a PAL script compiler configured for Bolt .
# TODO: If we always call this inside a bolt_executor we can remove this here # Only load the project if it a) exists, b) has a name it can be loaded with # Because this has the side effect of loading and caching the list # of modules, it must happen *after* we have overridden # bolt_project or the project will be ignored # Plans may return PuppetError but nothing should be throwing them
compiler_params
<not_specific>