Puppet Function: hash2props

Defined in:
lib/puppet/parser/functions/hash2props.rb
Function type:
Ruby 3.x API

Overview

hash2props()Any

Accepts a hash of Abiquo properties and returns a string to be used as content for properties file. Also needs which section of the properties file it represents.

For example:

$test = hash2props($section, $myhash)

Returns:

  • (Any)


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/puppet/parser/functions/hash2props.rb', line 3

newfunction(:hash2props, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
  Accepts a hash of Abiquo properties and returns a string to be used as content for properties file.
  Also needs which section of the properties file it represents.

  For example:

      $test = hash2props($section, $myhash)
  ENDHEREDOC

  unless args.length == 2
    raise Puppet::ParseError, ("hash2props(): wrong number of arguments (#{args.length}; must be 2)")
  end
  lines = []
  lines << "[#{args[0]}]"
  
  props = args[1]
  props.keys.each do |prop|
    line = "#{prop} = #{props[prop]}"
    lines << line
  end
  lines << ""

  lines.join("\n").sort
end