Puppet Function: wmflib::resource::dump_params

Defined in:
modules/wmflib/lib/puppet/functions/wmflib/resource/dump_params.rb
Function type:
Ruby 4.x API

Summary

this function is used to get a list of parameters passed to a resource, excluding the name parameter. This allows one to easily transform parameters into a json or yaml config file. or pass them directly from profile to a core class.

Overview

wmflib::resource::dump_params()Any

SPDX-License-Identifier: Apache-2.0

Examples:

file { '/etc/foo/config.yaml':
  ensure => file,
  content => wmflib::resource::dump_params.to_yaml
}

Returns:

  • (Any)


10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'modules/wmflib/lib/puppet/functions/wmflib/resource/dump_params.rb', line 10

Puppet::Functions.create_function(:'wmflib::resource::dump_params', Puppet::Functions::InternalFunction) do
  dispatch :dump_params do
    scope_param
  end

  def dump_params(scope)
    params = scope.resource.to_hash.collect{|k, v| [k.to_s, v]}.to_h
    params.delete('name')
    params
    # TODO: when ruby 2.5 everywhere
    # scope.resource.to_hash.transform_keys(&:to_s)
  end
end