Add missing new files from commit 131e09855e06
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / functions / to_yaml.rb
diff --git a/3rdparty/modules/stdlib/lib/puppet/functions/to_yaml.rb b/3rdparty/modules/stdlib/lib/puppet/functions/to_yaml.rb
new file mode 100644 (file)
index 0000000..fdd7370
--- /dev/null
@@ -0,0 +1,21 @@
+# Take a data structure and output it as YAML
+#
+# @example how to output YAML
+#   # output yaml to a file
+#     file { '/tmp/my.yaml':
+#       ensure  => file,
+#       content => to_yaml($myhash),
+#     }
+#
+#
+require 'yaml'
+
+Puppet::Functions.create_function(:to_yaml) do
+  dispatch :to_yaml do
+    param 'Any', :data
+  end
+
+  def to_yaml(data)
+    data.to_yaml
+  end
+end