title: md5 Hash in a puppet custom function
body: <p>Currently I want to create an md5 hash from an argument. Then I want to write the hash into a file (the path is another argument).</p>
  
  <p>That is the custom function:</p>
  
  <pre><code>   module Puppet::Parser::Functions
        newfunction(:write_line_to_file) do |args|
      require 'md5'
          filename = args[0]
  
          str = MD5.new(lookupvar(args[1])).to_s
          File.open(filename, 'a') {|fd| fd.puts str }
        end
      end
  </code></pre>
  
  <p>And the call in the puppet manifest:</p>
  
  <pre><code>write_line_to_file('/tmp/some_hash', "Hello world!")
  </code></pre>
  
  <p>The result I get is a file and the content is not the hash but the original string. (In the example Hello World!)</p>
  
  <p>I know that this custom function has no practical use. I just want to understand how the md5 hash works.  </p>
  
  <p>---UPD---</p>
  
  <p>new Function (it works properly):</p>
  
  <pre><code>   require 'digest'
     module Puppet::Parser::Functions
        newfunction(:lxwrite_line_to_file) do |args|
          filename = args[0]
  
          str = Digest::MD5.hexdigest args[1]
          File.open(filename, 'w') {|fd| fd.puts str }
        end
      end
  </code></pre>