Skip to content

Instantly share code, notes, and snippets.

@jaimegago
Last active May 24, 2016 04:27
Show Gist options
  • Save jaimegago/6de65aa1f2f632919f67467ba882dabe to your computer and use it in GitHub Desktop.
Save jaimegago/6de65aa1f2f632919f67467ba882dabe to your computer and use it in GitHub Desktop.
chef_lib_hash_to_string
# This goes in <my_app_coobkook>/libraries/default.rb
class Chef
class Resource
def hash_to_s hash
hash.map do |k,v|
k.to_s + '=' + v.to_s
end.join("\n") + "\n"
end
end
end
###
## and this is how you use it in a recipe
file <path_to_file> do
content hash_to_s(my_hash)
end
# Say you have path_to_file='/tmp/myfile'
# and my_hash = { 'quote' => 'to be or not to be' }
# it would create a file /tmp/myfile which content would be quote=to be or not to be
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment