Method: Puppet::Pal.in_tmp_environment

Defined in:
lib/puppet/pal/pal_impl.rb

.in_tmp_environment(env_name, modulepath: [], settings_hash: {}, facts: nil, variables: {}) {|context,| ... } ⇒ Object

Defines the context in which to perform puppet operations (evaluation, etc) The code to evaluate in this context is given in a block.

Parameters:

  • env_name (String)

    a name to use for the temporary environment - this only shows up in errors

  • modulepath (Array<String>) (defaults to: [])

    an array of directory paths containing Puppet modules, may be empty, defaults to empty array

  • settings_hash (Hash) (defaults to: {})

    a hash of settings - currently not used for anything, defaults to empty hash

  • facts (Hash) (defaults to: nil)

    optional map of fact name to fact value - if not given will initialize the facts (which is a slow operation)

  • variables (Hash) (defaults to: {})

    optional map of fully qualified variable name to value

Yield Parameters:

  • context, (Puppet::Pal)

    a context that responds to Puppet::Pal methods

Returns:

  • (Object)

    returns what the given block returns



230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/puppet/pal/pal_impl.rb', line 230

def self.in_tmp_environment(env_name,
                            modulepath:    [],
                            settings_hash: {},
                            facts:         nil,
                            variables:     {},
                            &block)
  assert_non_empty_string(env_name, _("temporary environment name"))
  # TRANSLATORS: do not translate variable name string in these assertions
  assert_optionally_empty_array(modulepath, 'modulepath')

  unless block_given?
    raise ArgumentError, _("A block must be given to 'in_tmp_environment'") # TRANSLATORS 'in_tmp_environment' is a name, do not translate
  end

  env = Puppet::Node::Environment.create(env_name, modulepath)

  in_environment_context(
    Puppet::Environments::Static.new(env), # The tmp env is the only known env
    env, facts, variables, &block
  )
end