summaryrefslogtreecommitdiff
path: root/lib/puppet/functions/to_yaml.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet/functions/to_yaml.rb')
-rw-r--r--lib/puppet/functions/to_yaml.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/puppet/functions/to_yaml.rb b/lib/puppet/functions/to_yaml.rb
new file mode 100644
index 0000000..fdd7370
--- /dev/null
+++ b/lib/puppet/functions/to_yaml.rb
@@ -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