Puppet Function: kibana::hash2yaml

Defined in:
lib/puppet/functions/kibana/hash2yaml.rb
Function type:
Ruby 4.x API

Summary

Converts a puppet hash to YAML string.

Overview

kibana::hash2yaml(Hash $input, Optional[Hash] $options)String

Examples:

Call the function with the $input hash

kibana::hash2yaml($input)

Parameters:

  • input (Hash)

    The hash to be converted to YAML

  • options (Optional[Hash])

    A hash of options to control YAML file format

Returns:

  • (String)

    A YAML formatted string



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/puppet/functions/kibana/hash2yaml.rb', line 4

Puppet::Functions.create_function(:'kibana::hash2yaml') do
  # @param input The hash to be converted to YAML
  # @param options A hash of options to control YAML file format
  # @return [String] A YAML formatted string
  # @example Call the function with the $input hash
  #   kibana::hash2yaml($input)
  dispatch :yaml do
    param 'Hash', :input
    optional_param 'Hash', :options
  end

  require 'yaml'

  def yaml(input, options = {})
    settings = {
      'header' => '# File managed by Puppet.'
    }

    settings.merge!(options)

    if settings['header'].to_s.empty?
      input.to_yaml
    else
      "#{settings['header']}\n#{input.to_yaml}"
    end
  end
end