Puppet Function: to_yaml

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

Overview

to_yaml(Any $data, Optional[Hash] $options)String

}

Parameters:

  • data (Any)

    The data you want to convert to YAML

  • options (Optional[Hash])

    A hash of options that will be passed to Ruby’s Psych library. Note, this could change between Puppet versions, but at time of writing these are ‘line_width`, `indentation`, and `canonical`.

Returns:

  • (String)

    The YAML document



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/puppet/functions/to_yaml.rb', line 17

Puppet::Functions.create_function(:to_yaml) do
  # @param data
  #   The data you want to convert to YAML
  # @param options
  #   A hash of options that will be passed to Ruby's Psych library. Note, this could change between Puppet versions, but at time of writing these are `line_width`, `indentation`, and `canonical`.
  #
  # @return [String] The YAML document
  dispatch :to_yaml do
    param 'Any', :data
    optional_param 'Hash', :options
  end

  def to_yaml(data, options = {})
    data.to_yaml(options.transform_keys(&:to_sym))
  end
end